mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Fix vared of indexed value
You can use an index with vared, like `vared PATH[4]`. However this was
inadverently broken in fa2450db30
, because you cannot use `read` to
modify an element of a variable, only the whole variable. Fix this.
Unfortunately this means using another local variable, so we name it
__fish_vared_temp_value instead of just temp so that collisions are
unlikely.
This commit is contained in:
parent
b94600d181
commit
1bba97984b
1 changed files with 9 additions and 2 deletions
|
@ -17,8 +17,10 @@ function vared --description "Edit variable value"
|
|||
|
||||
case '*'
|
||||
if test (count $$argv ) -lt 2
|
||||
# Avoid using any local variables in this function, otherwise they can't be edited
|
||||
# Try to avoid using local variables in this function, otherwise they can't be edited.
|
||||
# https://github.com/fish-shell/fish-shell/issues/8836
|
||||
# However we need to use one local, as you can't read directly into an index (like vared PATH[4]).
|
||||
set -l __fish_vared_temp_value
|
||||
|
||||
# The command substitution in this line controls the scope.
|
||||
# If variable already exists, do not add any switches, so we don't change
|
||||
|
@ -28,7 +30,12 @@ function vared --description "Edit variable value"
|
|||
read -p 'set_color green; echo '$argv'; set_color normal; echo "> "' \
|
||||
(if not set -q $argv; echo -g; end) \
|
||||
-c "$$argv" \
|
||||
$argv
|
||||
__fish_vared_temp_value
|
||||
if test -n "$$argv"
|
||||
set $argv $__fish_vared_temp_value
|
||||
else
|
||||
set -g $argv $__fish_vared_temp_value
|
||||
end
|
||||
else
|
||||
printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv >&2
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue