X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=shell-completion%2Fzsh%2F_systemctl.in;h=7f2d5ac0fa689b7357bfdd3c13e2703f09b03391;hb=0289f2fb2a64df53b589b771f69c43126b029590;hp=d9b8d1c0e32b27d7938a15592ec898439df8a96e;hpb=c0a67aef31bb9716617ffe150ca8be19c5df203e;p=elogind.git diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index d9b8d1c0e..7f2d5ac0f 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -31,6 +31,10 @@ "disable:Disable one or more unit files" "reenable:Reenable one or more unit files" "preset:Enable/disable one or more unit files based on preset configuration" + "set-default:Set the default target" + "get-default:Query the default target" + "edit:Edit one or more unit files" + "is-system-running:Query overall status of the system" "help:Show documentation for specified units" "list-dependencies:Show unit dependency tree" "mask:Mask one or more units" @@ -100,7 +104,7 @@ _systemctl_all_units() if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) && ! _retrieve_cache SYS_ALL_UNITS; then - _sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo " $a"; done; }) ) + _sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do echo -E - " $a"; done; }) ) _store_cache SYS_ALL_UNITS _sys_all_units fi } @@ -113,7 +117,7 @@ _systemctl_really_all_units() if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) && ! _retrieve_cache SYS_REALLY_ALL_UNITS; then - all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo " $a"; done; }) ) + all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do echo -E - " $a"; done; }) ) _systemctl_all_units really_all_units=($_sys_all_units $all_unit_files) _sys_really_all_units=(${(u)really_all_units}) @@ -133,20 +137,40 @@ _filter_units_by_property() { unit=${units[i]} prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"} if [[ "${prop}" = "$property=$value" ]]; then - echo " ${unit}" + echo -E - " ${unit}" fi done } -_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo " $a"; done; }) )} -_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all | { while read a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo " $a"; done; }) )} -_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo " $a"; done; }) )} -_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "enabled" ]] && echo " $a"; done; }) )} -_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == "disabled" ]] && echo " $a"; done; }) )} -_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )} +_systemctl_get_template_names() { __systemctl list-unit-files | { while read -r a b; do [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } } + + +_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read -r a b; do echo -E - " $a"; done; }) )} + +_systemctl_startable_units(){ + _sys_startable_units=(_filter_units_by_property ActiveState inactive $( + _filter_units_by_property CanStart yes $( + __systemctl $mode list-unit-files --state enabled,disabled,static | \ + { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; } + __systemctl $mode list-units --state inactive,failed | \ + { while read -r a b; do echo -E - " $a"; done; } ))) +} + +_systemctl_restartable_units(){ + _sys_restartable_units=(_filter_units_by_property CanStart yes $( + __systemctl $mode list-unit-files --state enabled,disabled,static | \ + { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; } + __systemctl $mode list-units | \ + { while read -r a b; do echo -E - " $a"; done; } )) +} + +_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )} +_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )} +_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )} +_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) )} # Completion functions for ALL_UNITS -for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies ; do +for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies edit ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_really_all_units @@ -155,20 +179,24 @@ for fun in is-active is-failed is-enabled status show cat mask preset help list- done # Completion functions for ENABLED_UNITS -for fun in disable reenable ; do - (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() - { +(( $+functions[_systemctl_disable] )) || _systemctl_disable() +{ + _systemctl_enabled_units + compadd "$@" -a - _sys_enabled_units +} + +(( $+functions[_systemctl_reenable] )) || _systemctl_reenable() +{ _systemctl_enabled_units _systemctl_disabled_units - compadd "$@" -a - _sys_enabled_units _sys_disabled_units - } -done + compadd "$@" -a - _sys_enabled_units _sys_disabled_units $(_systemctl_get_template_names) +} # Completion functions for DISABLED_UNITS (( $+functions[_systemctl_enable] )) || _systemctl_enable() { _systemctl_disabled_units - compadd "$@" -a - _sys_disabled_units + compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names) } # Completion functions for FAILED_UNITS @@ -181,8 +209,8 @@ done # Completion functions for STARTABLE_UNITS (( $+functions[_systemctl_start] )) || _systemctl_start() { - _systemctl_inactive_units - compadd "$@" -a - _sys_inactive_units + _systemctl_startable_units + compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names) } # Completion functions for STOPPABLE_UNITS @@ -217,11 +245,8 @@ done for fun in restart reload-or-restart ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { - _systemctl_all_units - compadd "$@" - $( _filter_units_by_property CanStart yes \ - ${_sys_all_units[*]} | while read line; do \ - [[ "$line" =~ \.device$ ]] || echo " $line"; \ - done ) + _systemctl_restartable_units + compadd "$@" - ${_sys_restartable_units[*]} $(_systemctl_get_template_names) } done @@ -229,21 +254,28 @@ done (( $+functions[_systemctl_unmask] )) || _systemctl_unmask() { _systemctl_masked_units - compadd "$@" -a - _sys_masked_units || _message "no masked unit found" + compadd "$@" -a - _sys_masked_units || _message "no masked units found" } # Completion functions for JOBS (( $+functions[_systemctl_cancel] )) || _systemctl_cancel() { compadd "$@" - $(__systemctl list-jobs \ - | cut -d' ' -f1 2>/dev/null ) || _message "no job found" + | cut -d' ' -f1 2>/dev/null ) || _message "no jobs found" } # Completion functions for SNAPSHOTS (( $+functions[_systemctl_delete] )) || _systemctl_delete() { compadd "$@" - $(__systemctl list-units --type snapshot --all \ - | cut -d' ' -f1 2>/dev/null ) || _message "no snapshot found" + | cut -d' ' -f1 2>/dev/null ) || _message "no snapshots found" +} + +# Completion functions for TARGETS +(( $+functions[_systemctl_set-default] )) || _systemctl_set-default() +{ + compadd "$@" - $(__systemctl list-unit-files --type target --all \ + | cut -d' ' -f1 2>/dev/null ) || _message "no targets found" } # Completion functions for ENVS @@ -261,7 +293,9 @@ for fun in set-environment unset-environment ; do } done -(( $+functions[_systemctl_link] )) || _systemctl_link() { _files } +(( $+functions[_systemctl_link] )) || _systemctl_link() { + _sd_unit_files +} # no systemctl completion for: # [STANDALONE]='daemon-reexec daemon-reload default @@ -297,7 +331,7 @@ _unit_states() { _unit_types() { local -a _types - _types=(automount device mount path service snapshot socket swap target timer) + _types=(automount busname device mount path service snapshot socket swap target timer) _values -s , "${_types[@]}" }