mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
abbr: Add "-q"/"--query" option
[ci skip]
This commit is contained in:
parent
38f37b7abc
commit
8a93c7d0ea
2 changed files with 18 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue