mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 07:42:45 +08:00
alias: Use source
directly
The extra things `eval` does are all for code that runs interactively. Because we just define a function, we don't need it. This improves alias' performance by about 20-25% (0.783608s to 0.585585s on about 500 aliases) and avoids triggering #3345.
This commit is contained in:
parent
eeb42f5e54
commit
443fc66048
|
@ -40,9 +40,9 @@ function alias --description 'Legacy function for creating shellscript functions
|
|||
end
|
||||
|
||||
# Extract the first command from the body
|
||||
# This is supposed to replace all non-escaped (i.e. preceded by an odd number of `\`) spaces with a newline
|
||||
# so it splits on them
|
||||
set -l tmp (string replace -ra "([^\\\ ])((\\\\\\\)*) " '$1\n' $body)
|
||||
# This is supposed to replace all non-escaped (i.e. preceded by an odd number of `\`) spaces with a newline
|
||||
# so it splits on them
|
||||
set -l tmp (string replace -ra "([^\\\ ])((\\\\\\\)*) " '$1\n' $body)
|
||||
set first_word (string trim $tmp[1])
|
||||
if set -q tmp[2]
|
||||
set body $tmp[2..-1]
|
||||
|
@ -60,6 +60,5 @@ function alias --description 'Legacy function for creating shellscript functions
|
|||
set prefix command
|
||||
end
|
||||
end
|
||||
eval "function $name --wraps $first_word; $prefix $first_word $body \$argv; end"
|
||||
echo "function $name --wraps $first_word; $prefix $first_word $body \$argv; end" | source
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user