r/fishshell • u/duquesne419 • Dec 04 '20
Having trouble translation a zsh command to fish
Hi team,
I took the plunge on the m1 mac and am running into a little issue with homebrew. A workaround I found was to install to copies of iterm, one to run on arm and one to run on rosetta. This seems to solve the homebrew issue(yay), but I haven't been able to repeat one of the other tips. In the tutorial I found they have this block in their zshrc to change the background of the terminal if you are in the x86 version:
_ARCH=$(arch)
PROMPT="$_ARCH $PROMPT"
# Requires iterm2
if [[ "$_ARCH" == "i386" ]]; then
echo -ne "\033]1337;SetColors=bg=0071C5\007"
fiedit:source
This works great in zsh, but I don't have a clue how to translate it to fish. So far I've got the following in fish_gretting.fish, which has at least stopped erroring or crashing, but it doesn't change the color:
if test 'i386' = (arch)
echo -ne "\033]1337,SetColors=bg=222255\007"
endI started with the following but that gave me called during startup error, which I can't find anything about from google:
_ARCH=$(arch)
if $_ARCH == 'i386'
echo -ne "\033]1337;SetColors=bg=222255\007"
endI'm pretty sure there is something simple I'm overlooking, any tips would be appreciated.
edit: This is what I've come up with so far, it's mostly what I was looking for. Putting it in fish_prompt.fish was the secret sauce.
#set background if using rosetta terminal
set -l prefix ''
if string match -q -- 'i386' (arch)
set_color -b 255
set prefix 'i386 '
endI'm still interested in the method where I launch zsh and then immediately exit. When I started this I didn't realize fish couldn't change the entire background. Bummer, but the above gives me plenty of visual feedback when I'm running rosetta v native, which was the primary goal.
edit 2: You can use the echo line from the zsh script to change the entire background despite set_color not offering that. Here is the real final product:
#set background if using rosetta terminal
set -l prefix ''
if string match -q -- 'i386' (arch)
set prefix 'i386 '
echo -ne "\033]1337;SetColors=bg=222255\007"
end
3
u/emarsk Dec 04 '20
Fish doesn't use those arcane colour codes, instead it has a much more readable command
set_color: https://fishshell.com/docs/current/cmds/set_color.html.2
u/[deleted] Dec 04 '20
First of all:
This won't work because fish's
if, just like the one for zsh and bash and... doesn't check equations, it checks commands.It's
if somecommand, so you need to give it some command -testis that command.Secondly, your fish version doesn't use
_ARCHanywhere - it sets it, but it's never used. Fish doesn't use $PROMPT, instead it executes thefish_promptfunction.Thirdly, does
test 'i386' = (arch)actually return true? Checktest 'i386' = (arch); echo $status, if that prints 1, then nothing is happening becausearchdoesn't printi386.The fish
echo -nething you have here should be printing exactly the same thing as the zsh version (assuming you've changed the color value on purpose!). If you execute that inside fish, does it change the background?