1
0
mirror of https://github.com/systemd/systemd synced 2024-07-09 04:26:06 +00:00
systemd/shell-completion/zsh/_systemd-inhibit
Eisuke Kawashima 20927c0eec
improve zsh completion (#32098)
* fix error
* remove options that are no longer supported
* add missing options
* stop completion if an option `--help` or `--version` is supplied

[[[
zjs: a note for the reader:

zshcompsys(1) in the section about optspecs in _arguments says:

> Each of the forms above may be preceded by a list in parentheses of option names  and  argument  num‐
> bers.  If the given option is on the command line, the options and arguments indicated in parentheses
> will not be offered.  For example, ‘(-two -three 1)-one:...' completes the option ‘-one'; if this ap‐
> pears  on  the  command line, the options -two and -three and the first ordinary argument will not be
> completed after it.  ‘(-foo):...' specifies an ordinary argument completion; -foo will  not  be  com‐
> pleted if that argument is already present.
> 
> Other  items  may  appear in the list of excluded options to indicate various other items that should
> not be applied when the current specification is matched: a single star (\*) for  the  rest  arguments
> (i.e. a specification of the form ‘\*:...'); a colon (:) for all normal (non-option-) arguments; and a
> hyphen (-) for all options.  For example, if ‘(\*)' appears before an option and the option appears on
> the  command  line,  the  list  of remaining arguments (those shown in the above table beginning with
> ‘\*:') will not be completed.

The intended effect of the change is to remove irrelevant completion matches from the completion.

tl;dr: (- : ) prevents further completion
]]]
2024-04-15 10:58:48 +02:00

39 lines
1.3 KiB
Plaintext

#compdef systemd-inhibit
# SPDX-License-Identifier: LGPL-2.1-or-later
(( $+functions[_systemd-inhibit_commands] )) ||
_systemd-inhibit_commands(){
if (( CURRENT == 1 )); then
compset -q
_normal
else
local n=${words[(b:2:i)[^-]*]}
if (( n <= CURRENT )); then
compset -n $n
_alternative \
'files:file:_files' \
'commands:command:_normal' && return 0
fi
_default
fi
}
(( $+functions[_systemd-inhibit_what] )) ||
_systemd-inhibit_what() {
local _inhibit
_inhibit=(shutdown sleep idle handle-power-key handle-suspend-key handle-hibernate-key handle-lid-switch)
_values -s : "${_inhibit[@]}"
}
_arguments \
'(- *)'{-h,--help}'[Show this help]' \
'(- *)--version[Show package version]' \
'--no-pager[Do not pipe output into a pager]' \
'--no-legend[Do not show the headers and footers]' \
'--what=[Operations to inhibit]:options:_systemd-inhibit_what' \
'--who=[A descriptive string who is inhibiting]:who is inhibiting:' \
'--why=[A descriptive string why is being inhibited]:reason for the lock:' \
'--mode=[One of block or delay]:lock mode:( block delay )' \
'--list[List active inhibitors]' \
'*:commands:_systemd-inhibit_commands'