zsh-completion: Move machine listing to autoload
Instead of having two different listings of machines, use an autoloaded function that can be used by other shell completions in the future. It will also allow editing a single file to change the way machinectl and systemd-run completion for machines.
This commit is contained in:
parent
a02c5fe7cb
commit
c0fd7cbd7a
|
@ -19,12 +19,7 @@
|
|||
case $cmd in
|
||||
list) msg="no options" ;;
|
||||
*)
|
||||
_machines=( "${(foa)$(machinectl list | awk '{print $1}')}" )
|
||||
if [[ -n "$_machines" ]]; then
|
||||
_describe 'machines' _machines
|
||||
else
|
||||
_message 'no machines'
|
||||
fi
|
||||
_sd_machines
|
||||
esac
|
||||
else
|
||||
_message "no more options"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#autoload
|
||||
__get_machines () {
|
||||
machinectl --full --no-pager list | {while read -r a b; do echo $a; done;};
|
||||
}
|
||||
|
||||
local -a _machines
|
||||
_machines=("${(fo)$(__get_machines)}")
|
||||
typeset -U _machines
|
||||
if [[ -n "$_machines" ]]; then
|
||||
_describe 'machines' _machines
|
||||
else
|
||||
_message 'no machines'
|
||||
fi
|
|
@ -18,27 +18,12 @@ __slices () {
|
|||
_describe 'slices' _slices
|
||||
}
|
||||
|
||||
__get_machines () {
|
||||
machinectl --full --no-pager list | {while read -r a b; do echo $a; done;};
|
||||
}
|
||||
|
||||
__machines () {
|
||||
local -a _machines
|
||||
_machines=("${(fo)$(__get_machines)}")
|
||||
typeset -U _machines
|
||||
if [[ -n "$_machines" ]]; then
|
||||
_describe 'machines' _machines
|
||||
else
|
||||
_message 'no machines'
|
||||
fi
|
||||
}
|
||||
|
||||
_arguments \
|
||||
{-h,--help}'[Show help message]' \
|
||||
'--version[Show package version]' \
|
||||
'--user[Run as user unit]' \
|
||||
{-H+,--host=}'[Operate on remote host]:[user@]host:_sd_hosts_or_user_at_host' \
|
||||
{-M+,--machine=}'[Operate on local container]:machines:__machines' \
|
||||
{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
|
||||
'--scope[Run this as scope rather than service]' \
|
||||
'--unit=[Run under the specified unit name]:unit name' \
|
||||
'--description=[Description for unit]:description' \
|
||||
|
|
Loading…
Reference in New Issue