mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
vared: avoid using local variables
The tmp and prompt variables collide with variables used as arguments. Just avoid them entirely, at the cost of making the internals of the functions somewhat more complicated. Closes #8836.
This commit is contained in:
parent
cc689290cd
commit
fa2450db30
|
@ -35,6 +35,7 @@ Interactive improvements
|
||||||
- ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`).
|
- ``less`` and other interactive commands would occasionally be stopped when run in a pipeline with fish functions; this has been fixed (:issue:`8699`).
|
||||||
- Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`).
|
- Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`).
|
||||||
- ``ulimit`` learned a number of new options for the resource limits available on Linux, FreeBSD and NetBSD, and returns a specific warning if the limit specified is not available on the active operating system (:issue:`8823`).
|
- ``ulimit`` learned a number of new options for the resource limits available on Linux, FreeBSD and NetBSD, and returns a specific warning if the limit specified is not available on the active operating system (:issue:`8823`).
|
||||||
|
- The ``vared`` command can now successfully edit variables named "tmp" or "prompt" (:issue:`8836`).
|
||||||
|
|
||||||
New or improved bindings
|
New or improved bindings
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -17,25 +17,18 @@ function vared --description "Edit variable value"
|
||||||
|
|
||||||
case '*'
|
case '*'
|
||||||
if test (count $$argv ) -lt 2
|
if test (count $$argv ) -lt 2
|
||||||
set -l init ''
|
# Avoid using any local variables in this function, otherwise they can't be edited
|
||||||
if test -n "$$argv"
|
# https://github.com/fish-shell/fish-shell/issues/8836
|
||||||
set init $$argv
|
|
||||||
end
|
|
||||||
set -l prompt 'set_color green; echo '$argv'; set_color normal; echo "> "'
|
|
||||||
if read -p $prompt -c $init tmp
|
|
||||||
|
|
||||||
# If variable already exists, do not add any
|
# The command substitution in this line controls the scope.
|
||||||
# switches, so we don't change export rules. But
|
# If variable already exists, do not add any switches, so we don't change
|
||||||
# if it does not exist, we make the variable
|
# scoping or export rules. But if it does not exist, we make the variable
|
||||||
# global, so that it will not die when this
|
# global, so that it will not die when this function dies.
|
||||||
# function dies
|
|
||||||
|
|
||||||
if test -n "$$argv"
|
read -p 'set_color green; echo '$argv'; set_color normal; echo "> "' \
|
||||||
set $argv $tmp
|
(if not set -q $argv; echo -g; end) \
|
||||||
else
|
-c "$$argv" \
|
||||||
set -g $argv $tmp
|
$argv
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user