X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=shell-completion%2Fzsh%2F_systemctl.in;h=7f2d5ac0fa689b7357bfdd3c13e2703f09b03391;hp=44981fe85d8d020df31e181e7ce53dafa12891b0;hb=557b5d4a94967198b3181fcb83879d4569cbf456;hpb=1cf3c30c0787f941b0f6d0b11ab504ddee3b0b8f diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index 44981fe85..7f2d5ac0f 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -33,6 +33,7 @@ "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" @@ -136,25 +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_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $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=($(__systemctl list-units --state inactive,failed -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )} -_systemctl_restartable_units(){_sys_restartable_units=($(__systemctl list-units --state inactive,failed,active -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && 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 @@ -194,8 +210,7 @@ done (( $+functions[_systemctl_start] )) || _systemctl_start() { _systemctl_startable_units - compadd "$@" - $( _filter_units_by_property CanStart yes \ - ${_sys_startable_units[*]} ) + compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names) } # Completion functions for STOPPABLE_UNITS @@ -231,8 +246,7 @@ for fun in restart reload-or-restart ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_restartable_units - compadd "$@" - $( _filter_units_by_property CanStart yes \ - ${_sys_restartable_units[*]} ) + compadd "$@" - ${_sys_restartable_units[*]} $(_systemctl_get_template_names) } done