Skip to content

Commit

Permalink
Rearrange the PATH to respect the order defined in /etc/paths (#927) and
Browse files Browse the repository at this point in the history
to prepend it to $PATH instead of appending it (#950)
  • Loading branch information
ridiculousfish committed Aug 25, 2013
1 parent a8af974 commit dead45f
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions share/config.fish
Expand Up @@ -57,41 +57,44 @@ if test -d /usr/xpg4/bin
end
end

# 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
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
set -l local_path $PATH
set -l x
for x in $__fish_added_user_paths
if set -l idx (contains --index $x $local_path)
set -e local_path[$idx]
end
end

set -e __fish_added_user_paths
for x in $fish_user_paths[-1..1]
if not contains $x $local_path
set local_path $x $local_path
set -g __fish_added_user_paths $__fish_added_user_paths $x
end
end
set -xg PATH $local_path
end
__fish_reconstruct_path

# 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
if not contains $new_path_comp $PATH
set PATH $PATH $new_path_comp
end
# 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
if test -r /etc/paths ; __fish_load_path_helper_paths < /etc/paths ; 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
# 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
set -l local_path $PATH
set -l x
for x in $__fish_added_user_paths
set -l idx (contains --index $x $local_path)
and set -e local_path[$idx]
end

set -e __fish_added_user_paths
for x in $fish_user_paths[-1..1]
if not contains $x $local_path
set local_path $x $local_path
set -g __fish_added_user_paths $__fish_added_user_paths $x
end
end
set -xg PATH $local_path
end
__fish_reconstruct_path

#
# Launch debugger on SIGTRAP
#
Expand Down

0 comments on commit dead45f

Please sign in to comment.