正如以利亚所言,最佳实践是修改fish_user_paths
而不是全局PATH
。为了避免再次使用Google……
- 创建几个只能修改的功能
fish_user_paths
- 使两个功能自动加载
要添加到用户路径:
function addpaths
contains -- $argv $fish_user_paths
or set -U fish_user_paths $fish_user_paths $argv
echo "Updated PATH: $PATH"
end
删除用户路径( 如果存在)(部分功劳于此):
function removepath
if set -l index (contains -i $argv[1] $PATH)
set --erase --universal fish_user_paths[$index]
echo "Updated PATH: $PATH"
else
echo "$argv[1] not found in PATH: $PATH"
end
end
当然,要使其自动加载:
funcsave addpaths; funcsave removepath
用法示例:
> addpaths /etc /usr/libexec
Modifying PATH: /usr/local/bin /usr/bin /bin /usr/sbin /sbin
Updated PATH: /etc /usr/libexec /usr/local/bin /usr/bin /bin /usr/sbin /sbin
> removepath /usr/libexec
Modifying PATH: /etc /usr/libexec /usr/local/bin /usr/bin /bin /usr/sbin /sbin
Updated PATH: /etc /usr/local/bin /usr/bin /bin /usr/sbin /sbin
grep -R /usr/lib/x86_64-linux-gnu/libfm ~/.config/fish /usr/share/fish
??