Fish Shell Tips

Useful tips for working with the fish shell. Fish manages user-defined paths through a universal variable called fish_user_paths.

PATH Management

Add to PATH

Use fish_add_path to add a directory. It updates fish_user_paths persistently and avoids duplicates:

fish_add_path /path/to/add

Use -v to print the underlying set command that is executed, and verify the result:

fish_add_path -v /path/to/add
echo $fish_user_paths | tr " " "\n" | nl

View current PATH entries

echo $fish_user_paths | tr " " "\n" | nl

Remove from PATH

Use contains -i to look up the index of the entry you want to remove and erase it in one step:

set --erase --universal fish_user_paths[(contains -i /path/to/remove $fish_user_paths)]

This avoids the two-step process of listing entries and manually entering the index number.

Note: fish_user_paths is a universal variable, meaning changes persist across all fish sessions automatically.