From 443fc660484ec6768226144aaf1dc6f2744687de Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 1 Sep 2016 12:27:10 +0200 Subject: [PATCH] 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. --- share/functions/alias.fish | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 11fdd164f..6a4973823 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -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 -