X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=shell-completion%2Fzsh%2F_systemctl.in;h=1435dee7243315462fb598dd4fb681f6cc8860f2;hb=5ba43716f345e205eba33156c0171fb657f4451f;hp=d364d17dd9004dd256e98fa2862c3857d53021a4;hpb=2c12a402cb1e8277c271ced8dc9c06d20b8f6017;p=elogind.git diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index d364d17dd..1435dee72 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -100,7 +100,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 +113,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}) @@ -138,12 +138,17 @@ _filter_units_by_property() { 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_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_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 @@ -155,20 +160,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 +190,9 @@ done # Completion functions for STARTABLE_UNITS (( $+functions[_systemctl_start] )) || _systemctl_start() { - _systemctl_inactive_units - compadd "$@" -a - _sys_inactive_units + _systemctl_startable_units + compadd "$@" - $( _filter_units_by_property CanStart yes \ + ${_sys_startable_units[*]} ) } # Completion functions for STOPPABLE_UNITS @@ -217,11 +227,9 @@ done for fun in restart reload-or-restart ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { - _systemctl_all_units + _systemctl_restartable_units compadd "$@" - $( _filter_units_by_property CanStart yes \ - ${_sys_all_units[*]} | while read line; do \ - [[ "$line" =~ \.device$ ]] || echo " $line"; \ - done ) + ${_sys_restartable_units[*]} ) } done