Search code examples
laravelcomposer-phpfish

Path setup in Fish shell


Laravel requires to set path. It's done by

export PATH="$PATH:$HOME/.composer/vendor/bin"

in bash but I need it be done in fish shell persistently. I tried to set it by set -u in ~/.config/fish/config.fish but doesn't work.


Solution

  • In fish, $PATH, $MANPATH and $CDPATH are automatically converted to lists.

    That means the fish-native equivalent of your command (which will actually work as it is in 2.6.0 because fish ships a export compatibility function) is

    set -gx PATH $PATH $HOME/.composer/vendor/bin
    

    Now, you do not want to set $PATH universally. You also pretty much can't, because it is inherited from the parent process in 99% of cases as a global variable, and global variables override universals (meaning the univeral variable is pointless).

    However, fish has a $fish_user_paths universal variable that it will prepend to $PATH, so you can also use

    set -U fish_user_paths $HOME/.composer/vendor/bin
    

    If you need to append instead, you'll need to add that $PATH snippet above to your config.fish.