Skip to content

Commit

Permalink
test: Add a new --quiet flag to suppress output
Browse files Browse the repository at this point in the history
The --quiet flag is useful when only the exit status matters.

Fix the documentation for the -t flag to no longer claim that `type` can
print "keyword", as it never does that.

Stop printing a blank line for functions/builtins when the -p flag has
been passed. It's just not useful.
  • Loading branch information
lilyball committed Jul 14, 2014
1 parent 6b062b0 commit 6f7a745
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion doc_src/type.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ The following options are available:
- \c -h or \c --help prints help and then exits.
- \c -a or \c --all prints all of possible definitions of the specified names.
- \c -f or \c --no-functions suppresses function and builtin lookup.
- \c -t or \c --type prints <tt>keyword</tt>, <tt>function</tt>, <tt>builtin</tt>, or <tt>file</tt> if \c NAME is a shell reserved word, function, builtin, or disk file, respectively.
- \c -t or \c --type prints <tt>function</tt>, <tt>builtin</tt>, or <tt>file</tt> if \c NAME is a shell function, builtin, or disk file, respectively.
- \c -p or \c --path returns the name of the disk file that would be executed, or nothing if 'type -t name' would not return 'file'.
- \c -P or \c --force-path returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the <tt>$PATH</tt>.
- \c -q or \c --quiet suppresses all output; this is useful when testing the exit status.

\c type sets the exit status to 0 if the specified command was found,
and 1 if it could not be found.
Expand Down
24 changes: 13 additions & 11 deletions share/functions/type.fish
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ function type --description "Print the type of a command"
for i in (seq (count $argv))
switch $argv[$i]
case -t --type
set mode type
if test $mode != quiet
set mode type
end

case -p --path
set mode path
if test $mode != quiet
set mode path
end

case -P --force-path
set mode path
if test $mode != quiet
set mode path
end
set selection files

case -a --all
Expand All @@ -28,6 +34,9 @@ function type --description "Print the type of a command"
case -f --no-functions
set selection files

case -q --quiet
set mode quiet

case -h --help
__fish_print_help type
return 0
Expand Down Expand Up @@ -61,10 +70,6 @@ function type --description "Print the type of a command"

case type
echo (_ 'function')

case path
echo

end
if test $multi != yes
continue
Expand All @@ -81,9 +86,6 @@ function type --description "Print the type of a command"

case type
echo (_ 'builtin')

case path
echo
end
if test $multi != yes
continue
Expand Down Expand Up @@ -116,7 +118,7 @@ function type --description "Print the type of a command"
end
end

if test $found = 0
if begin; test $found = 0; and test $mode != quiet; end
printf (_ "%s: Could not find '%s'\n") type $i >&2
end

Expand Down

0 comments on commit 6f7a745

Please sign in to comment.