mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
Let command, jobs and type take --query
instead of --quiet
Now command, jobs, type, abbr, builtin, functions and set take `-q` to query for existence, but the long option is inconsistent. The first three use `--quiet`, the latter use `--query`. Add `--query` to the first three, but keep `--quiet` around. Fixes #7276.
This commit is contained in:
parent
6ca2dbecfb
commit
bfb5b28d0f
11 changed files with 41 additions and 7 deletions
|
@ -73,6 +73,7 @@ Scripting improvements
|
|||
file descriptor. This allows better error recovery and is more in line with other shells'
|
||||
behaviour (#7038).
|
||||
- ``jobs --quiet PID`` no longer prints "no suitable job" if the job for PID does not exist (eg because it has finished) (#6809).
|
||||
- All builtins that query if something exists now take ``--query`` as the long form for ``-q``. ``--quiet`` is deprecated for ``command``, ``jobs`` and ``type`` (#7276).
|
||||
|
||||
Interactive improvements
|
||||
------------------------
|
||||
|
|
|
@ -19,7 +19,7 @@ The following options are available:
|
|||
|
||||
- ``-a`` or ``--all`` returns all the external COMMANDNAMEs that are found in ``$PATH`` in the order they are found.
|
||||
|
||||
- ``-q`` or ``--quiet``, silences the output and prints nothing, setting only the exit status. Implies ``--search``.
|
||||
- ``-q`` or ``--query``, silences the output and prints nothing, setting only the exit status. Implies ``--search``. For compatibility with old fish versions this is also ``--quiet`` (but this is deprecated).
|
||||
|
||||
- ``-s`` or ``--search`` returns the name of the external command that would be executed, or nothing if no file with the specified name could be found in the ``$PATH``.
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ jobs accepts the following switches:
|
|||
|
||||
- ``-p`` or ``--pid`` prints the process ID for each process in all jobs.
|
||||
|
||||
- ``-q`` or ``--quiet`` prints no output for evaluation of jobs by exit status only.
|
||||
- ``-q`` or ``--query`` prints no output for evaluation of jobs by exit status only. For compatibility with old fish versions this is also ``--quiet`` (but this is deprecated).
|
||||
|
||||
On systems that supports this feature, jobs will print the CPU usage of each job since the last command was executed. The CPU usage is expressed as a percentage of full CPU activity. Note that on multiprocessor systems, the total activity may be more than 100\%.
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ The following options are available:
|
|||
|
||||
- ``-P`` or ``--force-path`` returns the path to the executable file ``NAME``, presuming ``NAME`` is found in ``$PATH``, or nothing otherwise. ``--force-path`` explicitly resolves only the path to executable files in ``$PATH``, regardless of whether ``$NAME`` is shadowed by a function or builtin with the same name.
|
||||
|
||||
- ``-q`` or ``--quiet`` suppresses all output; this is useful when testing the exit status.
|
||||
- ``-q`` or ``--query`` suppresses all output; this is useful when testing the exit status. For compatibility with old fish versions this is also ``--quiet``.
|
||||
|
||||
The ``-q``, ``-p``, ``-t`` and ``-P`` flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time.
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
complete -c command -n 'test (count (commandline -opc)) -eq 1' -s h -l help -d 'Display help and exit'
|
||||
complete -c command -n 'test (count (commandline -opc)) -eq 1' -s a -l all -d 'Print all external commands by the given name'
|
||||
complete -c command -n 'test (count (commandline -opc)) -eq 1' -s q -l quiet -d 'Do not print anything, only set exit status'
|
||||
complete -c command -n 'test (count (commandline -opc)) -eq 1' -s q -l quiet -l query -d 'Do not print anything, only set exit status'
|
||||
complete -c command -n 'test (count (commandline -opc)) -eq 1' -s s -l search -d 'Print the file that would be executed'
|
||||
complete -c command -xa "(__fish_complete_subcommand)"
|
||||
|
|
|
@ -5,3 +5,4 @@ complete -c jobs -s p -l pid -d "Show the process id of each process in the job"
|
|||
complete -c jobs -s g -l group -d "Show group id of job"
|
||||
complete -c jobs -s c -l command -d "Show commandname of each job"
|
||||
complete -c jobs -s l -l last -d "Only show status for last job to be started"
|
||||
complete -c jobs -s q -l quiet -l query -d "Check if a job exists without output"
|
||||
|
|
|
@ -5,7 +5,7 @@ complete -c type -s f -l no-functions -d "Suppress function and builtin lookup"
|
|||
complete -c type -s t -l type -d "Print command type"
|
||||
complete -c type -s p -l path -d "Print path to command, or nothing if name is not a command"
|
||||
complete -c type -s P -l force-path -d "Print path to command"
|
||||
complete -c type -s q -l quiet -d "Suppress output"
|
||||
complete -c type -s q -l query -l quiet -d "Check if something exists without output"
|
||||
|
||||
complete -c type -a "(builtin -n)" -d Builtin
|
||||
complete -c type -a "(functions -n)" -d Function
|
||||
|
|
|
@ -3,7 +3,8 @@ function type --description 'Print the type of a command'
|
|||
set -q argv[1]
|
||||
or return 1
|
||||
|
||||
set -l options h/help a/all s/short f/no-functions t/type p/path P/force-path q/quiet
|
||||
# --query is the same thing as --quiet
|
||||
set -l options h/help a/all s/short f/no-functions t/type p/path P/force-path q/quiet Q-query
|
||||
argparse -n type -x t,p,P $options -- $argv
|
||||
or return
|
||||
|
||||
|
@ -21,7 +22,7 @@ function type --description 'Print the type of a command'
|
|||
# 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
|
||||
# --quiet have precedence.
|
||||
if set -q _flag_quiet
|
||||
if set -q _flag_quiet; or set -q _flag_query
|
||||
set mode quiet
|
||||
else if set -q _flag_type
|
||||
set mode type
|
||||
|
|
|
@ -26,6 +26,7 @@ static const wchar_t *const short_options = L":ahqsv";
|
|||
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
|
||||
{L"all", no_argument, nullptr, 'a'},
|
||||
{L"quiet", no_argument, nullptr, 'q'},
|
||||
{L"query", no_argument, nullptr, 'q'},
|
||||
{L"search", no_argument, nullptr, 's'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **arg
|
|||
{L"last", no_argument, nullptr, 'l'},
|
||||
{L"pid", no_argument, nullptr, 'p'},
|
||||
{L"quiet", no_argument, nullptr, 'q'},
|
||||
{L"query", no_argument, nullptr, 'q'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
int opt;
|
||||
|
|
|
@ -446,3 +446,32 @@ echo not#a#comment
|
|||
#CHECK: not#a#comment
|
||||
echo is # a # comment
|
||||
#CHECK: is
|
||||
|
||||
# Test that our builtins can all do --query
|
||||
command --query cp
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
||||
type --query cp
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
||||
jobs --query 0
|
||||
echo $status
|
||||
#CHECK: 1
|
||||
|
||||
abbr --query thisshouldnotbeanabbreviationohmygoshitssolongwhywouldanyoneeverusethis
|
||||
echo $status
|
||||
#CHECK: 1
|
||||
|
||||
functions --query alias
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
||||
set --query status
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
||||
builtin --query echo
|
||||
echo $status
|
||||
#CHECK: 0
|
||||
|
|
Loading…
Reference in a new issue