On Wed, 21 Jun 2023, 沈 乐宸 wrote:

> I'm a Fish Shell newbie, and this question has already annoyed me for 
> several hours. I look through the man pages, and I tried these:
> · set -gx PATH $PATH[2..]
> · set -U PATH $PATH[2..]
> and non of these works (they did work in the current shell, but when I 
> open a new shell, the path wasn't modified).

The first command will remove the element from the PATH in the global 
scope, but as you have noticed, that only affects the currently running 
shell.

Trying to modify PATH as a universal variable generally will not work. 
When the shell starts, it inherits its existing environment variables as 
global variables, and will almost always be started with a PATH variable. 
This global variable will overshadow the universal variable.

If you want to make this permanent, I suggest you try and work out where 
the PATH element that you want to erase is coming from, and modify it at 
the source. One possibility is the fish_user_paths universal variable, and 
if you modify that it should be reflected in all new shells.

Alternatively, you can unset it in your ~/.config/fish/config.fish. I'd be 
careful with just wiping the first element - better to use something like:

if contains /unwanted/path -- $PATH
   set --erase PATH[(contains --index /unwanted/path $PATH)]
done

Hope that helps.

David Adam
zanc...@ucc.gu.uwa.edu.au
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to