aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/type.fish
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-07-14 11:19:59 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-07-14 11:27:11 -0700
commit16e50c258a5d5cecc76e1f2dc29a62be88a1ac2f (patch)
tree3aacef8ff8475a676eb6347d7e1821586f7d2fa2 /share/functions/type.fish
parentcce4265cef63132f7e398f7cf89a63d8078a9c2e (diff)
type: Restore combined flags behavior
Fix the parsing of `type` flags to handle combined short flags as appropriate, e.g. `type -qf ls`.
Diffstat (limited to 'share/functions/type.fish')
-rw-r--r--share/functions/type.fish101
1 files changed, 61 insertions, 40 deletions
diff --git a/share/functions/type.fish b/share/functions/type.fish
index 8992d6b2..e7bc7b28 100644
--- a/share/functions/type.fish
+++ b/share/functions/type.fish
@@ -11,44 +11,65 @@ 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]
- case -t --type
- if test $mode != quiet
- set mode type
- end
-
- case -p --path
- if test $mode != quiet
- set mode path
- end
-
- case -P --force-path
- if test $mode != quiet
- set mode path
- end
- set selection files
-
- case -a --all
- set multi yes
-
- case -f --no-functions
- set selection files
-
- case -q --quiet
- set mode quiet
-
- case -h --help
- __fish_print_help type
- return 0
-
- case --
- set names $argv[$i..-1]
- set -e names[1]
- break
-
- case '*'
- set names $argv[$i..-1]
- break
+ 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
+ end
+
+ case -p --path
+ if test $mode != quiet
+ set mode path
+ end
+
+ case -P --force-path
+ if test $mode != quiet
+ set mode path
+ end
+ set selection files
+
+ case -a --all
+ set multi yes
+
+ case -f --no-functions
+ set selection files
+
+ case -q --quiet
+ set mode quiet
+
+ case -h --help
+ __fish_print_help type
+ return 0
+
+ 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
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