Sample Header Ad - 728x90

Remove certain path from $PATH

1 vote
1 answer
262 views
To add something to $PATH in fish, I use
fish_add_path -a ~/foo/bar
Then fish adds ~/foo/bar to my ~/.config/fish/fish_variables:
SETUVAR fish_user_paths:/Users/john/foo/bar
Then, is it correct to say that to remove /Users/john/foo/bar from $PATH, I have two options: - to edit the fish_variables file - to use the following function:
// https://github.com/fish-shell/fish-shell/issues/8604#issuecomment-1169638533 
  function remove_path
    if set -l index (contains -i "$argv" $fish_user_paths)
      set -e fish_user_paths[$index]
      echo "Removed $argv from the path"
    end
  end
And the second part of the question: How to properly use that function? I saved it as remove_from_path.fish, executed as remove_from_path.fish "/Users/john/foo/bar", but it doesn't seem to remove /Users/john/foo/bar from $PATH. What I'm doing wrong?
Asked by jsx97 (1347 rep)
Mar 5, 2025, 01:20 PM
Last activity: Mar 5, 2025, 02:28 PM