type: Restore combined flags behavior

Fix the parsing of `type` flags to handle combined short flags as
appropriate, e.g. `type -qf ls`.
This commit is contained in:
Kevin Ballard 2014-07-14 11:19:59 -07:00
parent cce4265cef
commit 16e50c258a

View file

@ -11,7 +11,22 @@ function type --description "Print the type of a command"
set -l names
if test (count $argv) -gt 0
for i in (seq (count $argv))
switch $argv[$i]
set -l arg $argv[$i]
set -l needbreak 0
while test -n $arg
set -l flag $arg
set arg ''
switch $flag
case '--*'
# do nothing; this just prevents it matching the next case
case '-??*'
# combined flags
set -l IFS
echo -n $flag | read _ flag arg
set flag -$flag
set arg -$arg
end
switch $flag
case -t --type
if test $mode != quiet
set mode type
@ -44,10 +59,16 @@ function type --description "Print the type of a command"
case --
set names $argv[$i..-1]
set -e names[1]
set needbreak 1
break
case '*'
set names $argv[$i..-1]
set needbreak 1
break
end
end
if test $needbreak -eq 1
break
end
end
@ -96,9 +117,9 @@ function type --description "Print the type of a command"
set -l paths
if test $multi != yes
set paths (command -s $i)
set paths (command -s -- $i)
else
set paths (which -a $i ^/dev/null)
set paths (which -a -- $i ^/dev/null)
end
for path in $paths
set res 0