optimize 'alias', fixing bug #486. Also some minor optimizations in 'type'

This commit is contained in:
Jan Kanis 2013-02-05 20:43:40 +01:00
parent e918851902
commit e8da9999f6
2 changed files with 16 additions and 9 deletions

View file

@ -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"

View file

@ -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