diff --git a/share/config.fish b/share/config.fish index 2c1f8b526..e7ca703f4 100644 --- a/share/config.fish +++ b/share/config.fish @@ -57,41 +57,44 @@ if test -d /usr/xpg4/bin 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 # 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 + 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 + 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/* -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 #