diff options
author | Jan Kanis <jan.code@jankanis.nl> | 2013-02-05 20:43:40 +0100 |
---|---|---|
committer | Jan Kanis <jan.code@jankanis.nl> | 2013-02-05 23:14:06 +0100 |
commit | e8da9999f61c7133b7387b9311068f432cbc8c47 (patch) | |
tree | e38f7c9d00cbd28b3f71bfdb421e777fa941badb | |
parent | e9188519023e9ae13f0c5eb97f499ba9a4c9ca85 (diff) |
optimize 'alias', fixing bug #486. Also some minor optimizations in 'type'
-rw-r--r-- | share/functions/alias.fish | 17 | ||||
-rw-r--r-- | share/functions/type.fish | 8 |
2 files changed, 16 insertions, 9 deletions
diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 4b72ecd2..b6597ee2 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -35,11 +35,18 @@ function alias --description "Legacy function for creating shellscript functions return 1 end - switch (type -t $name) - case file - set prefix command - case builtin - set prefix builtin + + # If we are shadowing an existing (internal or external) command, set the + # correct prefix. If $name is different from the command in $body, we assume + # the user knows what he/she is doing. + + switch $body + case $name $name\ \* $name\t\* + if contains $name (builtin --names) + set prefix builtin + else if which $name >/dev/null + set prefix command + end end eval "function $name; $prefix $body \$argv; end" diff --git a/share/functions/type.fish b/share/functions/type.fish index 94c77efa..6eb1a66f 100644 --- a/share/functions/type.fish +++ b/share/functions/type.fish @@ -85,10 +85,10 @@ function type --description "Print the type of a command" functions $i case type - printf (_ 'function\n') + echo (_ 'function') case path - echo + echo end if test $selection != multi @@ -105,7 +105,7 @@ function type --description "Print the type of a command" printf (_ '%s is a builtin\n') $i case type - printf (_ 'builtin\n') + echo (_ 'builtin') case path echo @@ -126,7 +126,7 @@ function type --description "Print the type of a command" printf (_ '%s is %s\n') $i $path case type - printf (_ 'file\n') + echo (_ 'file') case path echo $path |