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 return 1
end end
switch (type -t $name)
case file # If we are shadowing an existing (internal or external) command, set the
set prefix command # correct prefix. If $name is different from the command in $body, we assume
case builtin # the user knows what he/she is doing.
set prefix builtin
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 end
eval "function $name; $prefix $body \$argv; 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 functions $i
case type case type
printf (_ 'function\n') echo (_ 'function')
case path case path
echo echo
end end
if test $selection != multi if test $selection != multi
@ -105,7 +105,7 @@ function type --description "Print the type of a command"
printf (_ '%s is a builtin\n') $i printf (_ '%s is a builtin\n') $i
case type case type
printf (_ 'builtin\n') echo (_ 'builtin')
case path case path
echo echo
@ -126,7 +126,7 @@ function type --description "Print the type of a command"
printf (_ '%s is %s\n') $i $path printf (_ '%s is %s\n') $i $path
case type case type
printf (_ 'file\n') echo (_ 'file')
case path case path
echo $path echo $path