diff --git a/share/functions/fish_add_path.fish b/share/functions/fish_add_path.fish index 3b2ef96f5..21151c1e8 100644 --- a/share/functions/fish_add_path.fish +++ b/share/functions/fish_add_path.fish @@ -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 diff --git a/tests/checks/fish_add_path.fish b/tests/checks/fish_add_path.fish index 948498e3b..44e0bee6f 100644 --- a/tests/checks/fish_add_path.fish +++ b/tests/checks/fish_add_path.fish @@ -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