From bfb5b28d0f69fe499817d21b1811c3083f76445d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 4 Sep 2020 16:41:34 +0200 Subject: [PATCH] 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. --- CHANGELOG.rst | 1 + doc_src/cmds/command.rst | 2 +- doc_src/cmds/jobs.rst | 2 +- doc_src/cmds/type.rst | 2 +- share/completions/command.fish | 2 +- share/completions/jobs.fish | 1 + share/completions/type.fish | 2 +- share/functions/type.fish | 5 +++-- src/builtin_command.cpp | 1 + src/builtin_jobs.cpp | 1 + tests/checks/basic.fish | 29 +++++++++++++++++++++++++++++ 11 files changed, 41 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3ca13c719..79bacb9f9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------------ diff --git a/doc_src/cmds/command.rst b/doc_src/cmds/command.rst index b1df173fc..7e1368dd2 100644 --- a/doc_src/cmds/command.rst +++ b/doc_src/cmds/command.rst @@ -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``. diff --git a/doc_src/cmds/jobs.rst b/doc_src/cmds/jobs.rst index b072377db..2de6ee17c 100644 --- a/doc_src/cmds/jobs.rst +++ b/doc_src/cmds/jobs.rst @@ -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\%. diff --git a/doc_src/cmds/type.rst b/doc_src/cmds/type.rst index c362abe3c..03436cd26 100644 --- a/doc_src/cmds/type.rst +++ b/doc_src/cmds/type.rst @@ -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. diff --git a/share/completions/command.fish b/share/completions/command.fish index ea35aaa06..2ad0c39ba 100644 --- a/share/completions/command.fish +++ b/share/completions/command.fish @@ -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)" diff --git a/share/completions/jobs.fish b/share/completions/jobs.fish index 8ce3ab94f..96ad91ae0 100644 --- a/share/completions/jobs.fish +++ b/share/completions/jobs.fish @@ -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" diff --git a/share/completions/type.fish b/share/completions/type.fish index 9c42dd603..209db6b87 100644 --- a/share/completions/type.fish +++ b/share/completions/type.fish @@ -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 diff --git a/share/functions/type.fish b/share/functions/type.fish index f957dfe07..21010e676 100644 --- a/share/functions/type.fish +++ b/share/functions/type.fish @@ -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 diff --git a/src/builtin_command.cpp b/src/builtin_command.cpp index 462e33a84..e4aba80a9 100644 --- a/src/builtin_command.cpp +++ b/src/builtin_command.cpp @@ -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}}; diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index 8248c3c5f..f440399e9 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -135,6 +135,7 @@ maybe_t 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; diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 3e554e5e7..2c231040b 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -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