fish_add_path: Also deduplicate the new paths

Previously, running `fish_add_path /foo /foo` would result in /foo
being added to $PATH twice.

Now we check that it hasn't already been given, so we skip the
second (and any further) occurence.
This commit is contained in:
Fabian Homborg 2022-05-17 17:02:46 +02:00
parent 54356da24f
commit b71416f610
2 changed files with 5 additions and 2 deletions

View file

@ -58,11 +58,11 @@ function fish_add_path --description "Add paths to the PATH"
if set -l ind (contains -i -- $p $$var)
# In move-mode, we remove it from its current position and add it back.
if set -q _flag_move
if set -q _flag_move; and not contains -- $p $newpaths
set -a indexes $ind
set -a newpaths $p
end
else
else if not contains -- $p $newpaths
# Without move, we only add it if it's not in.
set -a newpaths $p
end

View file

@ -58,4 +58,7 @@ or echo "PATH CHANGED!!!" >&2
PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/{link,sbin} | string replace -a $tmpdir ''
# CHECK: set -g PATH /link /sbin /bin /etc
# See that trying to add a path twice doesn't duplicate it
PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/sbin{,} | string replace -a $tmpdir ''
# CHECK: set -g PATH /sbin /link /bin /etc
exit 0