mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Don't use a function variable in alias
This conditionally set a function variable in an unsafe way.
If you do something like
```fish
if condition
set -f foo bar
end
```
then, if the condition was false, $foo could still use a global variable.
In this case, alias would now fail if a variable $wraps was defined globally.
This reverts most of commit 14458682d9
.
The message rewording can stay, it's *fine* (tho it'll break the
translations but then we'd need a real string freeze with a
translation team for those to be worth anything anyway, soo)
This commit is contained in:
parent
7031a736a7
commit
789b2010f5
1 changed files with 9 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
function alias --description 'Creates a function wrapping a command'
|
||||
set -l options h/help s/save
|
||||
argparse --max-args=2 $options -- $argv
|
||||
argparse -n alias --max-args=2 $options -- $argv
|
||||
or return
|
||||
|
||||
if set -q _flag_help
|
||||
|
@ -55,18 +55,17 @@ function alias --description 'Creates a function wrapping a command'
|
|||
else
|
||||
set prefix command
|
||||
end
|
||||
else
|
||||
# Do not define wrapper completion if we have "alias foo 'foo xyz'" or "alias foo 'sudo foo'"
|
||||
# This is to prevent completions from recursively calling themselves (#7389).
|
||||
# The latter will have rare false positives but it's more important to
|
||||
# prevent recursion for this high-level command.
|
||||
if test $last_word != $name
|
||||
set -f wraps --wraps (string escape -- $body)
|
||||
end
|
||||
end
|
||||
set -l cmd_string (string escape -- "alias $argv")
|
||||
|
||||
|
||||
# Do not define wrapper completion if we have "alias foo 'foo xyz'" or "alias foo 'sudo foo'"
|
||||
# This is to prevent completions from recursively calling themselves (#7389).
|
||||
# The latter will have rare false positives but it's more important to
|
||||
# prevent recursion for this high-level command.
|
||||
set -l wraps
|
||||
if test $first_word != $name; and test $last_word != $name
|
||||
set wraps --wraps (string escape -- $body)
|
||||
end
|
||||
|
||||
echo "function $name $wraps --description $cmd_string; $prefix $body \$argv; end" | source
|
||||
if set -q _flag_save
|
||||
|
|
Loading…
Reference in a new issue