diff --git a/CHANGELOG.md b/CHANGELOG.md index e526c55b0..51ed110c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 51c6055a9..65224472f 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -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 diff --git a/tests/complete.err b/tests/complete.err index be4897027..b50147861 100644 --- a/tests/complete.err +++ b/tests/complete.err @@ -1,3 +1,6 @@ #################### # Completion Wrappers + +#################### +# Alias Completions diff --git a/tests/complete.in b/tests/complete.in index 844a270ed..857cc9deb 100644 --- a/tests/complete.in +++ b/tests/complete.in @@ -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 ' \ No newline at end of file diff --git a/tests/complete.out b/tests/complete.out index eb7a76658..419d0d3ac 100644 --- a/tests/complete.out +++ b/tests/complete.out @@ -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