mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 02:03:41 +08:00
Teach alias about wrap argument injection
Update the alias function to pass arguments to 'wraps'. For example alias gco='git checkout' now works like it ought to.
This commit is contained in:
parent
bb7b649132
commit
973533e374
|
@ -41,7 +41,7 @@ This section is for changes merged to the `major` branch that are not also merge
|
|||
- Tildes in file names are now properly escaped in completions (#2274)
|
||||
- A pipe at the end of a line now allows the job to continue on the next line (#1285)
|
||||
- The names `argparse`, `read`, `set`, `status`, `test` and `[` are now reserved and not allowed as function names. This prevents users unintentionally breaking stuff (#3000).
|
||||
- Wrapping completions (from `complete -w` or `function -w`) can now inject arguments. For example, `complete gco -w 'git checkout'` now works properly (#1976).
|
||||
- Wrapping completions (from `complete -w` or `function -w`) can now inject arguments. For example, `complete gco -w 'git checkout'` now works properly (#1976). The `alias` function has been updated to respect this behavior.
|
||||
|
||||
## Other significant changes
|
||||
- Command substitution output is now limited to 10 MB by default (#3822).
|
||||
|
|
|
@ -50,7 +50,7 @@ function alias --description 'Creates a function wrapping a command'
|
|||
set -l tmp (string replace -ra "([^\\\ ])((\\\\\\\)*) " '$1\n' $body)
|
||||
set first_word (string trim $tmp[1])
|
||||
# If the user does something like `alias x 'foo; bar'` we need to strip the semicolon.
|
||||
set wrapped_cmd (string trim -c ';' $first_word)
|
||||
set base_command (string trim -c ';' $first_word)
|
||||
if set -q tmp[2]
|
||||
set body $tmp[2..-1]
|
||||
else
|
||||
|
@ -59,7 +59,7 @@ function alias --description 'Creates a function wrapping a command'
|
|||
|
||||
# Prevent the alias from immediately running into an infinite recursion if
|
||||
# $body starts with the same command as $name.
|
||||
if test $wrapped_cmd = $name
|
||||
if test $base_command = $name
|
||||
if contains $name (builtin --names)
|
||||
set prefix builtin
|
||||
else
|
||||
|
@ -67,7 +67,7 @@ function alias --description 'Creates a function wrapping a command'
|
|||
end
|
||||
end
|
||||
set -l cmd_string (string escape "alias $argv")
|
||||
set wrapped_cmd (string escape $wrapped_cmd)
|
||||
set wrapped_cmd (string join ' ' $first_word $body | string escape)
|
||||
echo "function $name --wraps $wrapped_cmd --description $cmd_string; $prefix $first_word $body \$argv; end" | source
|
||||
#echo "function $name --wraps $wrapped_cmd --description $cmd_string; $prefix $first_word $body \$argv; end"
|
||||
end
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
|
||||
####################
|
||||
# Completion Wrappers
|
||||
|
||||
####################
|
||||
# Alias Completions
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
logmsg Completion Wrappers
|
||||
|
||||
function complete_test_alpha1; echo $argv; end
|
||||
|
||||
complete -c complete_test_alpha1 --no-files -a '(commandline)'
|
||||
complete -c complete_test_alpha2 --no-files -w 'complete_test_alpha1 extra1'
|
||||
complete -c complete_test_alpha3 --no-files -w 'complete_test_alpha2 extra2'
|
||||
|
@ -7,3 +9,13 @@ complete -c complete_test_alpha3 --no-files -w 'complete_test_alpha2 extra2'
|
|||
complete -C'complete_test_alpha1 arg1 '
|
||||
complete -C'complete_test_alpha2 arg2 '
|
||||
complete -C'complete_test_alpha3 arg3 '
|
||||
|
||||
logmsg Alias Completions
|
||||
|
||||
alias myalias1 'complete_test_alpha1 arg1'
|
||||
alias myalias2='complete_test_alpha1 arg2'
|
||||
|
||||
myalias1 call1
|
||||
myalias2 call2
|
||||
complete -C'myalias1 call3 '
|
||||
complete -C'myalias2 call3 '
|
|
@ -4,3 +4,10 @@
|
|||
complete_test_alpha1 arg1
|
||||
complete_test_alpha1 extra1 arg2
|
||||
complete_test_alpha1 extra1 extra2 arg3
|
||||
|
||||
####################
|
||||
# Alias Completions
|
||||
arg1 call1
|
||||
arg2 call2
|
||||
complete_test_alpha1 arg1 call3
|
||||
complete_test_alpha1 arg2 call3
|
||||
|
|
Loading…
Reference in New Issue
Block a user