re-use '~/.profile` for Fish?
You can use bash
to parse /etc/profile
and ~/.profile
, and then start fish.
Create
/usr/local/bin/fishlogin
with contents#!/bin/bash -l exec -l fish "$@"
Make it executable
sudo chmod a+rx /usr/local/bin/fishlogin
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.Add it to
/etc/shells
echo /usr/local/bin/fishlogin | sudo tee -a /etc/shells
Set it as your default shell.
Under Linux:
sudo usermod -s /usr/local/bin/fishlogin $USER
Under macOS:
chsh -s /usr/local/fishlogin $USER
For a much cleaner solution, you can use the foreign env plugin:
fenv source ~/.profile
My current solution (see here for a maybe more recent version):
egrep "^export " ~/.profile | while read e
set var (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\2/")
# remove surrounding quotes if existing
set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")
if test $var = "PATH"
# replace ":" by spaces. this is how PATH looks for Fish
set value (echo $value | sed -E "s/:/ /g")
# use eval because we need to expand the value
eval set -xg $var $value
continue
end
# evaluate variables. we can use eval because we most likely just used "$var"
set value (eval echo $value)
set -xg $var $value
end