mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Rearrange the PATH to respect the order defined in /etc/paths (#927) and
to prepend it to $PATH instead of appending it (#950)
This commit is contained in:
parent
a8af974895
commit
dead45fa67
1 changed files with 30 additions and 27 deletions
|
@ -57,41 +57,44 @@ if test -d /usr/xpg4/bin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# OS X-ism: Load the path files out of /etc/paths and /etc/paths.d/*
|
||||||
|
set -g __fish_tmp_path $PATH
|
||||||
|
function __fish_load_path_helper_paths
|
||||||
|
while read -l new_path_comp
|
||||||
|
# We want to rearrange the path to reflect this order. Delete that path component if it exists and then prepend it.
|
||||||
|
set -l where (contains -i $new_path_comp $__fish_tmp_path)
|
||||||
|
and set -e __fish_tmp_path[$where]
|
||||||
|
set __fish_tmp_path $new_path_comp $__fish_tmp_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
test -r /etc/paths ; and __fish_load_path_helper_paths < /etc/paths
|
||||||
|
for pathfile in /etc/paths.d/* ; __fish_load_path_helper_paths < $pathfile ; end
|
||||||
|
set -xg PATH $__fish_tmp_path
|
||||||
|
set -e __fish_tmp_path
|
||||||
|
functions -e __fish_load_path_helper_paths
|
||||||
|
|
||||||
|
|
||||||
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
|
||||||
# Invoke it immediately to apply the current value of fish_user_path
|
# Invoke it immediately to apply the current value of fish_user_path
|
||||||
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
||||||
set -l local_path $PATH
|
set -l local_path $PATH
|
||||||
set -l x
|
set -l x
|
||||||
for x in $__fish_added_user_paths
|
for x in $__fish_added_user_paths
|
||||||
if set -l idx (contains --index $x $local_path)
|
set -l idx (contains --index $x $local_path)
|
||||||
set -e local_path[$idx]
|
and set -e local_path[$idx]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
set -e __fish_added_user_paths
|
set -e __fish_added_user_paths
|
||||||
for x in $fish_user_paths[-1..1]
|
for x in $fish_user_paths[-1..1]
|
||||||
if not contains $x $local_path
|
if not contains $x $local_path
|
||||||
set local_path $x $local_path
|
set local_path $x $local_path
|
||||||
set -g __fish_added_user_paths $__fish_added_user_paths $x
|
set -g __fish_added_user_paths $__fish_added_user_paths $x
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set -xg PATH $local_path
|
set -xg PATH $local_path
|
||||||
end
|
end
|
||||||
__fish_reconstruct_path
|
__fish_reconstruct_path
|
||||||
|
|
||||||
# OS X-ism: Load the path files out of /etc/paths and /etc/paths.d/*
|
|
||||||
function __fish_load_path_helper_paths
|
|
||||||
while read -l new_path_comp
|
|
||||||
if not contains $new_path_comp $PATH
|
|
||||||
set PATH $PATH $new_path_comp
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if test -r /etc/paths ; __fish_load_path_helper_paths < /etc/paths ; end
|
|
||||||
for pathfile in /etc/paths.d/* ; __fish_load_path_helper_paths < $pathfile ; end
|
|
||||||
functions -e __fish_load_path_helper_paths
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Launch debugger on SIGTRAP
|
# Launch debugger on SIGTRAP
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue