Shell – re-use ‘~/.profile` for Fish?

(I’m talking about the shell Fish, esp. Fish’s Fish.)

For Bash/ZSH, I had ~/.profile with some exports, aliases and other stuff.

I don’t want to have a separate config for environment variables for Fish, I want to re-use my ~/.profile. How?

In The FAQ, it is stated that I can at least import those via /usr/local/share/fish/tools/import_bash_settings.py, however I don’t really like running that for each Fish-instance.

Solution:

You can use bash to parse /etc/profile and ~/.profile, and then start fish.

  1. Create /usr/local/bin/fishlogin with contents

     #!/bin/bash -l exec -l fish "$@"
  2. Make it executable

     sudo chmod a+rx /usr/local/bin/fishlogin
  3. Check that it works by running fishlogin and checking that you end up in a Fish shell. Press Control+D to exit the Fish shell.

  4. Add it to /etc/shells

     echo /usr/local/bin/fishlogin | sudo tee -a /etc/shells
  5. Set it as your default shell.

    Under Linux:

     sudo usermod -s /usr/local/bin/fishlogin $USER

    Under macOS:

     chsh -s /usr/local/fishlogin $USER