fish_add_path: Handle moving multiple arguments correctly

This `set -e` had a cartesian product that caused it to remove the
indexes separately, so the later indexes were off - removing the first
and then the second ends up removing the first and then the
old-*third* which is now the second.

Just quote the expansion so it runs in one go.

Fixes #7776
This commit is contained in:
Fabian Homborg 2021-03-04 16:10:27 +01:00
parent 76457bdc4e
commit d85bdf120f
2 changed files with 5 additions and 1 deletions

View File

@ -63,7 +63,7 @@ function fish_add_path --description "Add paths to the PATH"
set -l newvar $$var
if set -q _flag_move; and set -q indexes[1]
# We remove in one step, so the indexes don't move.
set -e newvar[$indexes]
set -e newvar["$indexes"]
end
set $mode newvar $newpaths

View File

@ -54,4 +54,8 @@ fish_add_path -nP $tmpdir/etc | string replace -- $tmpdir ''
test "$oldpath" = "$PATH"
or echo "PATH CHANGED!!!" >&2
# See that moving multiple arguments removes the correct ones - #7776
PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/{link,sbin} | string replace -a $tmpdir ''
# CHECK: set PATH /link /sbin /bin /etc
exit 0