简体   繁体   English

如何永久删除鱼$ PATH的路径?

[英]How to remove permanently a path from the fish $PATH?

This question has already been asked, and answered here: https://superuser.com/a/940041/293429 这个问题已经被提出,并在这里回答: https//superuser.com/a/940041/293429

However, the provided solution: executing set -e PATH[<index-of-the-path-to-be-removed] only applies to the running instance and is not valid universally. 但是,提供的解决方案:执行set -e PATH[<index-of-the-path-to-be-removed]仅适用于正在运行的实例,并且无法普遍有效。

After executing that command, if one executes echo $PATH the previously removed paths will occur again. 执行该命令后,如果执行echo $PATH ,则会再次发生先前删除的路径。

One way to completely reset the path is to execute: set -U fish_user_paths , but it is unclear to me that what it does. 完全重置路径的一种方法是执行: set -U fish_user_paths ,但我不清楚它的作用。

The real trick would be to find out how to remove a path which has been manually added and make it available globally -- not only for the current instance? 真正的诀窍是找出如何删除已手动添加的路径并使其全局可用 - 不仅仅是当前实例?

There's two ways to do this, and which one is valid depends on how the path got into $PATH. 有两种方法可以做到这一点,哪一种有效取决于路径如何进入$ PATH。

It is possible to add directories to $PATH via eg set PATH $PATH /some/dir . 可以通过例如set PATH $PATH /some/dir将目录添加到$ PATH。 At least by default, PATH is a global variable, which means it is per-session. 至少在默认情况下,PATH是一个全局变量,这意味着它是每个会话。 That means to change something from $PATH, either remove it from where it is added (which is likely outside of fish since it inherits it), or put the set -e call in your ~/.config/fish/config.fish so it will be executed on every start. 这意味着从$ PATH中更改一些内容,要么将其从添加它的位置删除(因为它继承了它可能在fish之外),或者将set -e调用放在〜/ .config / fish / config.fish中它会在每次开始时执行。

There is also $fish_user_paths, which is a universal variable (meaning it carries the same value across fish sessions and is synchronized across them). 还有$ fish_user_paths,它是一个通用变量(意味着它在fish会话中携带相同的值并在它们之间同步)。 On startup and whenever fish_user_paths is modified, fish adds it to $PATH. 在启动时以及修改fish_user_paths时,fish会将其添加到$ PATH。 If the offending directory is added here, execute set -e fish_user_paths[index] once (eg in an interactive session). 如果在此处添加了违规目录,则执行set -e fish_user_paths[index]一次(例如,在交互式会话中)。

set -e fish_user_paths would remove the entire variable (while set -U fish_user_paths would clear it) which would also work but would also remove all other paths set -e fish_user_paths将删除整个变量(虽然set -U fish_user_paths会清除它),这也可以工作,但也会删除所有其他路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM