alias: Escape the first word again

See https://stackoverflow.com/questions/63115744/alias-with-spaces-and-arguments-in-fish-3

This was broken in 115892ccd2
This commit is contained in:
Fabian Homborg 2020-07-27 17:18:51 +02:00
parent 7b5160e676
commit 84b25855b0
2 changed files with 13 additions and 0 deletions

View File

@ -57,6 +57,12 @@ function alias --description 'Creates a function wrapping a command'
end
end
set -l cmd_string (string escape -- "alias $argv")
# We've tokenized the first word, but we need to reescape them so they won't be split apart by `source`.
# E.g. if the first_word is "some command with spaces", that needs to be understood as one argument.
# As $body is the rest of the tokenized read, it doesn't need to be escaped.
set first_word (string escape -- $first_word)
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
if set -q _flag_save

View File

@ -24,3 +24,10 @@ alias | grep -Ev '^alias (fish_indent|fish_key_reader) '
# #4756 - missing "--" argument to string causing issues with "--" options
alias l. "ls -d .*"
# No output
alias d "'/mnt/c/Program Files (x86)/devenv.exe' /Edit"
functions d
# CHECK: # Defined in - @ line 1
# 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