diff options
Diffstat (limited to 'Completion/Unix/Command/_systemctl')
-rw-r--r-- | Completion/Unix/Command/_systemctl | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/Completion/Unix/Command/_systemctl b/Completion/Unix/Command/_systemctl index 801a8e060..69adcf775 100644 --- a/Completion/Unix/Command/_systemctl +++ b/Completion/Unix/Command/_systemctl @@ -33,6 +33,7 @@ _systemctl() '--no-block[Do not wait until operation finished]' \ "--no-wall[Don't send wall message before halt/power-off/reboot]" \ "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \ + '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \ '--no-pager[Do not pipe output into a pager]' \ '--no-ask-password[Do not ask for system passwords]' \ '--order[When generating graph for dot, show only order]' \ @@ -61,8 +62,10 @@ _hosts_or_user_at_host() "stop:Stop (deactivate) one or more units" "reload:Reload one or more units" "restart:Start or restart one or more units" + "condrestart:Restart one or more units if active" "try-restart:Restart one or more units if active" "reload-or-restart:Reload one or more units is possible, otherwise start or restart" + "force-reload:Reload one or more units is possible, otherwise restart if active" "reload-or-try-restart:Reload one or more units is possible, otherwise restart if active" "isolate:Start one unit and stop all others" "kill:Send signal to processes of a unit" @@ -125,34 +128,42 @@ _hosts_or_user_at_host() fi } +__check_option_nolegend() +{ + systemctl --no-legend --version 2>&1 | grep -q 'unrecognized option' + print -Pn '%(?..--no-legend)' +} +nolegend=$(__check_option_nolegend) + + # Fills the unit lists _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 --full --all | cut -d' ' -f1 \ - 2>/dev/null) ) + _sys_all_units=( $(systemctl ${nolegend} list-units --full --all \ + | cut -d' ' -f1 2>/dev/null) ) _store_cache SYS_ALL_UNITS _sys_all_units fi } _systemctl_inactive_units() { - _sys_inactive_units=( $(systemctl list-units --full --all \ - | awk '$3 != "active" {print $1}' 2>/dev/null) ) + _sys_inactive_units=( $(systemctl ${nolegend} list-units --full --all \ + | awk '$3 != "active" {print $1}' 2>/dev/null) ) } _systemctl_active_units() { - _sys_active_units=( $(systemctl list-units --full | cut -d' ' -f1 \ - 2>/dev/null) ) + _sys_active_units=( $(systemctl ${nolegend} list-units --full \ + | cut -d' ' -f1 2>/dev/null) ) } _systemctl_failed_units() { - _sys_failed_units=( $(systemctl list-units --full --failed | cut -d' ' -f1 - 2>/dev/null) ) + _sys_failed_units=( $(systemctl ${nolegend} list-units --full --failed \ + | cut -d' ' -f1 2>/dev/null) ) } _filter_units_by_property () { @@ -160,7 +171,7 @@ _filter_units_by_property () { local -a units ; units=($*) local -a props ; props=( $(systemctl show --property "$property" -- \ ${units[*]} | grep -v '^$') ) - for ((i=0; $i < ${#units[*]}; i++)); do + for ((i=1; $i <= ${#units[*]}; i++)); do if [[ "${props[i]}" = "$property=$value" ]]; then echo "${units[i]}" fi @@ -172,7 +183,7 @@ for fun in enable disable is-active is-enabled status show ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_all_units - compadd "$@" -a -- _sys_all_units + compadd "$@" -a - _sys_all_units } done @@ -180,7 +191,7 @@ done (( $+functions[_systemctl_start] )) || _systemctl_start() { _systemctl_inactive_units - compadd "$@" -- $( _filter_units_by_property CanStart yes \ + compadd "$@" - $( _filter_units_by_property CanStart yes \ ${_sys_inactive_units[*]} | grep -Ev '\.(device|snapshot)$' ) } @@ -189,7 +200,7 @@ for fun in restart reload-or-restart ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_all_units - compadd "$@" -- $( _filter_units_by_property CanStart yes \ + compadd "$@" - $( _filter_units_by_property CanStart yes \ ${_sys_all_units[*]} | grep -Ev '\.(device|snapshot|socket|timer)$' ) } done @@ -199,7 +210,7 @@ for fun in stop kill try-restart condrestart ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_active_units - compadd "$@" -- $( _filter_units_by_property CanStop yes \ + compadd "$@" - $( _filter_units_by_property CanStop yes \ ${_sys_active_units[*]} ) } done @@ -209,7 +220,7 @@ for fun in reload reload-or-try-restart force-reload ; do (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() { _systemctl_active_units - compadd "$@" -- $( _filter_units_by_property CanReload yes \ + compadd "$@" - $( _filter_units_by_property CanReload yes \ ${_sys_active_units[*]} ) } done @@ -218,7 +229,7 @@ done (( $+functions[_systemctl_isolate] )) || _systemctl_isolate() { _systemctl_all_units - compadd "$@" -- $( _filter_units_by_property AllowIsolate yes \ + compadd "$@" - $( _filter_units_by_property AllowIsolate yes \ ${_sys_all_units[*]} ) } @@ -226,34 +237,37 @@ done (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed() { _systemctl_failed_units - compadd "$@" -a -- _sys_failed_units || _message "no failed-unit found" + compadd "$@" -a - _sys_failed_units || _message "no failed-unit found" } # Completion functions for JOBS (( $+functions[_systemctl_cancel] )) || _systemctl_cancel() { - compadd "$@" -- $( systemctl list-jobs | cut -d' ' -f1 2>/dev/null ) || \ - _message "no job found" + compadd "$@" - $(systemctl ${nolegend} list-jobs \ + | cut -d' ' -f1 2>/dev/null ) || _message "no job found" } # Completion functions for SNAPSHOTS (( $+functions[_systemctl_delete] )) || _systemctl_delete() { - compadd "$@" -- $( systemctl list-units --type snapshot --full --all \ - | cut -d' ' -f1 2>/dev/null ) || _message "no snampshot found" + compadd "$@" - $(systemctl ${nolegend} list-units --type snapshot --full \ + --all | cut -d' ' -f1 2>/dev/null ) || _message "no snampshot found" } # Completion functions for ENVS -(( $+functions[_systemctl_set-environment] )) || _systemctl_set-environment() -{ - compadd "$@" -S '' -- $( systemctl show-environment \ - | sed 's_\([^=]\+=\).*_\1_' ) -} -(( $+functions[_systemctl_unset-environment] )) || _systemctl_unset-environment() -{ - compadd "$@" -S '' -- $( systemctl show-environment \ - | sed 's_\([^=]\+\)=.*_\1_' ) -} +for fun in set-environment unset-environment ; do + (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() + { + local fun=$0 ; fun=${fun##_systemctl_} + local suf + if [[ "${fun}" = "set-environment" ]]; then + suf='-S=' + fi + + compadd "$@" ${suf} - $(systemctl show-environment \ + | sed 's_\([^=]\+\)=.*_\1_' ) + } +done # no completion for: # [STANDALONE]='daemon-reexec daemon-reload default dot dump emergency exit @@ -270,7 +284,7 @@ _systemctl_caching_policy() oldcache=( "$1"(mh+1) ) (( $#oldcache )) && return 0 - _sysunits=($(systemctl --full --all | cut -d' ' -f1)) + _sysunits=($(systemctl ${nolegend} --full --all | cut -d' ' -f1)) if (( $#_sysunits )); then for unit in $_sysunits; do |