abbr: Add "-q"/"--query" option

[ci skip]
This commit is contained in:
Fabian Homborg 2019-02-19 10:06:17 +01:00
parent 38f37b7abc
commit 8a93c7d0ea
2 changed files with 18 additions and 3 deletions

View file

@ -7,6 +7,7 @@ abbr --erase word
abbr --rename [SCOPE] OLD_WORD NEW_WORD
abbr --show
abbr --list
abbr --query WORD..
\endfish
\subsection abbr-description Description
@ -29,6 +30,8 @@ The following options are available:
- `-e WORD` or `--erase WORD` Erase the abbreviation WORD.
- `-q` or `--query` Return 0 (true) if one of the WORDs is an abbreviation.
In addition, when adding abbreviations:
- `-g` or `--global` to use a global variable.

View file

@ -1,7 +1,7 @@
function abbr --description "Manage abbreviations"
set -l options --stop-nonopt --exclusive 'a,r,e,l,s' --exclusive 'g,U'
set -a options 'h/help' 'a/add' 'r/rename' 'e/erase' 'l/list' 's/show'
set -a options 'g/global' 'U/universal'
set -l options --stop-nonopt --exclusive 'a,r,e,l,s,q' --exclusive 'g,U'
set -a options h/help a/add r/rename e/erase l/list s/show q/query
set -a options g/global U/universal
argparse -n abbr $options -- $argv
or return
@ -20,6 +20,7 @@ function abbr --description "Manage abbreviations"
and not set -q _flag_erase[1]
and not set -q _flag_list[1]
and not set -q _flag_show[1]
and not set -q _flag_query[1]
if set -q argv[1]
set _flag_add --add
else
@ -49,6 +50,17 @@ function abbr --description "Manage abbreviations"
else if set -q _flag_show[1]
__fish_abbr_show $argv
return
else if set -q _flag_query[1]
# "--query": Check if abbrs exist.
# If we don't have an argument, it's an automatic failure.
set -q argv[1]; or return 1
set -l escaped _fish_abbr_(string escape --style=var -- $argv)
# We return 0 if any arg exists, whereas `set -q` returns the number of undefined arguments.
# But we should be consistent with `type -q` and `command -q`.
for var in $escaped
set -q $escaped; and return 0
end
return 1
else
printf ( _ "%s: Could not figure out what to do!\n" ) abbr >&2
return 127