diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 6588156b5..18e50db94 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -10,7 +10,6 @@ function alias --description 'Creates a function wrapping a command' set -l name set -l body - set -l prefix if not set -q argv[1] # Print the known aliases. @@ -51,9 +50,9 @@ function alias --description 'Creates a function wrapping a command' # $body starts with the same command as $name. if test $first_word = $name if contains $name (builtin --names) - set prefix builtin + set body "builtin $body" else - set prefix command + set body "command $body" end end set -l cmd_string (string escape -- "alias $argv") @@ -67,8 +66,8 @@ function alias --description 'Creates a function wrapping a command' set wraps --wraps (string escape -- $body) end - echo "function $name $wraps --description $cmd_string; $prefix $body \$argv - end" | source # The function definition in split in two lines to ensure that a '#' can be put in the body. + # The function definition in split in two lines to ensure that a '#' can be put in the body. + echo "function $name $wraps --description $cmd_string"\n"$body \$argv"\n"end" | source if set -q _flag_save funcsave $name end diff --git a/tests/checks/alias.fish b/tests/checks/alias.fish index dceb6c715..61c116c29 100644 --- a/tests/checks/alias.fish +++ b/tests/checks/alias.fish @@ -26,11 +26,11 @@ alias l. "ls -d .*" # No output alias d "'/mnt/c/Program Files (x86)/devenv.exe' /Edit" -functions d -# CHECK: # Defined via `source` -# CHECK: function d --wraps="'/mnt/c/Program Files (x86)/devenv.exe' /Edit" --description "alias d '/mnt/c/Program Files (x86)/devenv.exe' /Edit" -# CHECK: '/mnt/c/Program Files (x86)/devenv.exe' /Edit $argv -# CHECK: end +functions d | sed s,^,^, +# CHECK: ^# Defined via `source` +# CHECK: ^function d --wraps="'/mnt/c/Program Files (x86)/devenv.exe' /Edit" --description "alias d '/mnt/c/Program Files (x86)/devenv.exe' /Edit" +# CHECK: ^ '/mnt/c/Program Files (x86)/devenv.exe' /Edit $argv +# CHECK: ^end # Use "command" to prevent recursion, and don't add --wraps to avoid accidental recursion in completion. alias e 'e --option=value'