Skip to content

fish_add_path: set --erase incorrectly handles indices #7776

@branchv

Description

@branchv

While testing out the new fish_add_path --move, I noticed incorrect paths being removed/moved stemming from

set -e newvar[$indexes]

A simple repro is:

> set arr 1 2 3
> set -e arr[1] arr[2] # expanded form of arr[$indexes] above
> echo $arr
2 # expected 3

As you can see, set -e arr[1] works fine but presumably when set -e arr[2] occurs, arr = 2 3. The elements should be erased in index-descending order as set -e arr[1 2] correctly handles. Thus, a workaround for my initial issue is

diff --git a/share/functions/fish_add_path.fish b/share/functions/fish_add_path.fish
index cac0d9d4f..11e1017a0 100644
--- a/share/functions/fish_add_path.fish
+++ b/share/functions/fish_add_path.fish
@@ -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[(echo $indexes)]
     end
     set $mode newvar $newpaths
System info
> fish --version
fish, version 3.2.0

> uname -a
Darwin Branchs-MacBook-Pro.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

> echo $TERM
xterm-256color

> sh -c 'env HOME=$(mktemp -d) fish'
# reproduces

Btw, amazing work on fish! It is such a joy to use!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions