How can I make fish my default shell (without a nest of shells)?

After some head-scratching I now have flox running by default in my Ubuntu terminal. Previously I had fish (installed via apt) as my default shell and this seemed to cause problems. To resolve this I:

  • uninstalled fish from Ubuntu
  • reset my default shell to bash
  • created a default flox environment
  • added flox activate to .bashrc

I have also run flox install fish in my default environment so which fish returns:

/home/user/.cache/.../bin/fish

And I can manually run fish to launch the fish shell. Now I want to make fish my default flox shell.

According to Is it possible to set a different default shell? I should be able to update my .bashrc activation command. The following change does something:

eval "$(FLOX_SHELL=fish flox activate -r my/default)"

but it fails. As far as I can tell this is because bash is trying to parse a fish script:

bash: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
bash: /home/user/.cache/.../activate.d/fish: line 39: syntax error near unexpected token `if'
bash: /home/user/.cache/.../activate.d/fish: line 39: `  if test -e "$FLOX_ENV/activate.d/$i"'

I am also concerned that setting my default shell this way means I am creating a nightmare nest of processes:

bash > flox > bash > ??? > fish

What is the sensible way to make fish, as defined by flox, my default shell?

similar to the other post, are you able to upgrade to 3.7.1?

I follow up on that route in the other post. Although in this scenario, I wouldn’t bother installing fish on the base system and instead live in flox prompts powered by fish.

when running $(flox activate) flox will output a script suitable for the executing shell or, as in this case, FLOX_SHELL.
Effectively, eval "$(FLOX_SHELL=fish flox activate -r my/default)" in a bash shell, will result in flox outputting a fish script which is then evaluated by bashs eval i.e. as a bash script.
Since both shell dialects are not compatible you get bash errors.

I guess you could run something like FLOX_SHELL=fish exec flox activate -r my/default as the last thing in your bashrc. that would at least get you out of the nesting

bash > flox > fish

Whether one should do this is another question, considering the side effects that would have on other uses of bash expecting bashrcs to leave you in a bash shell…

Whether one should do this is another question

Indeed. I also ran into “The file specified the interpreter ‘/bin/fish’, which is not an executable command.” when trying to run a fish script, since /bin/fish no longer exists. I think I will leave this question of bootstrapping fish within flox for another day, and just use the system-provided version of fish.

I now have this working with system-installed fish and a simple change to config.fish. Full details…

Now whenever you launch a terminal, you should be in fish, and you should be able to run flox activate. To make it automatic, add the following line to $HOME/.config/fish/config.fish:

eval (flox activate --dir=$HOME) | source

Now whenever you launch a terminal, you should be in fish and your default environment should be activated (run flox list to confirm). And you can install all other tools with flox.

Also confirmed in gnome-system-monitor that I don’t have a chain of shells.

1 Like