Add the --short flag to type (#6403)

* Add the `--succinct` flag to `type`

* Use `echo` rather than `printf`

* Change `succinct` to `short`; print path if known

* Clean up the printing logic ever so slightly
This commit is contained in:
Dan Martinez 2019-12-11 13:24:29 -08:00 committed by Fabian Homborg
parent 0b53e51634
commit 16dc606001
2 changed files with 18 additions and 3 deletions

View File

@ -3,7 +3,7 @@ function type --description 'Print the type of a command'
set -q argv[1]
or return 1
set -l options 'h/help' 'a/all' 'f/no-functions' 't/type' 'p/path' 'P/force-path' 'q/quiet'
set -l options 'h/help' 'a/all' 's/short' 'f/no-functions' 't/type' 'p/path' 'P/force-path' 'q/quiet'
argparse -n type -x t,p,P $options -- $argv
or return
@ -16,6 +16,7 @@ function type --description 'Print the type of a command'
set -l mode normal
set -l multi no
set -l selection all
set -l short no
# Technically all four of these flags are mutually exclusive. However, we allow -q to be used
# with the other three because old versions of this function explicitly allowed it by making
@ -34,6 +35,9 @@ function type --description 'Print the type of a command'
set -q _flag_all
and set multi yes
set -q _flag_short
and set short yes
set -q _flag_no_functions
and set selection files
@ -48,8 +52,17 @@ function type --description 'Print the type of a command'
set found 1
switch $mode
case normal
printf (_ '%s is a function with definition\n') $i
functions $i
printf (_ '%s is a function') $i
if test $short != yes
echo (_ ' with definition')
functions $i
else
set -l func_path (functions --details $i)
if test $func_path != -
printf (_ ' (defined in %s)') $func_path
end
echo
end
case type
echo (_ 'function')
case path

View File

@ -20,6 +20,8 @@ The following options are available:
- ``-a`` or ``--all`` prints all of possible definitions of the specified names.
- ``-s`` or ``--short`` suppresses function expansion when used with no options or with ``-a``/``--all``.
- ``-f`` or ``--no-functions`` suppresses function and builtin lookup.
- ``-t`` or ``--type`` prints ``function``, ``builtin``, or ``file`` if ``NAME`` is a shell function, builtin, or disk file, respectively.