X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl-bash-completion.sh;h=6ebb792c0048fd67d0048473945096aa9de2332a;hb=7fc2a89a7387db1e5daa4892393c9e9536920c25;hp=f3420217b538640a55a75144686ff03988f9d337;hpb=e67c3609b18ab09499b361e18addfcfdec853fdd;p=elogind.git diff --git a/src/systemctl-bash-completion.sh b/src/systemctl-bash-completion.sh index f3420217b..6ebb792c0 100644 --- a/src/systemctl-bash-completion.sh +++ b/src/systemctl-bash-completion.sh @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License # along with systemd; If not, see . +__systemctl() { + systemctl --no-legend "$@" +} + __contains_word () { local word=$1; shift for w in $*; do [[ $w = $word ]] && return 0; done @@ -24,7 +28,7 @@ __contains_word () { __filter_units_by_property () { local property=$1 value=$2 ; shift ; shift local -a units=( $* ) - local -a props=( $(systemctl show --property "$property" -- ${units[*]} | grep -v ^$) ) + local -a props=( $(__systemctl show --property "$property" -- ${units[*]} | grep -v ^$) ) for ((i=0; $i < ${#units[*]}; i++)); do if [[ "${props[i]}" = "$property=$value" ]]; then echo "${units[i]}" @@ -32,10 +36,10 @@ __filter_units_by_property () { done } -__get_all_units () { systemctl list-units --full --all | awk ' {print $1}' ; } -__get_active_units () { systemctl list-units --full | awk ' {print $1}' ; } -__get_inactive_units () { systemctl list-units --full --all | awk '$3 == "inactive" {print $1}' ; } -__get_failed_units () { systemctl list-units --full | awk '$3 == "failed" {print $1}' ; } +__get_all_units () { __systemctl list-units --full --all | awk ' {print $1}' ; } +__get_active_units () { __systemctl list-units --full | awk ' {print $1}' ; } +__get_inactive_units () { __systemctl list-units --full --all | awk '$3 == "inactive" {print $1}' ; } +__get_failed_units () { __systemctl list-units --full | awk '$3 == "failed" {print $1}' ; } _systemctl () { local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} @@ -43,9 +47,9 @@ _systemctl () { local -A OPTS=( [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global - --help -h --no-ask-password --no-block --no-reload --no-wall - --order --require --quiet -q --system --user --version' - [ARG]='--kill-mode --kill-who --property -p --signal -s --type -t' + --help -h --no-ask-password --no-block --no-pager --no-reload --no-wall + --order --require --quiet -q --privileged -P --system --user --version' + [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t' ) if __contains_word "$prev" ${OPTS[ARG]}; then @@ -60,9 +64,9 @@ _systemctl () { comps='all control main' ;; --kill-mode) - comps='control-group process process-group' + comps='control-group process' ;; - --property|-p) + --property|-p|--host|-H) comps='' ;; esac @@ -79,10 +83,11 @@ _systemctl () { local -A VERBS=( [ALL_UNITS]='enable disable is-active is-enabled status show' [FAILED_UNITS]='reset-failed' - [STARTABLE_UNITS]='start restart reload-or-restart' + [STARTABLE_UNITS]='start' [STOPPABLE_UNITS]='stop kill try-restart condrestart' - [ISOLATEBLE_UNITS]='isolate' + [ISOLATABLE_UNITS]='isolate' [RELOADABLE_UNITS]='reload reload-or-try-restart force-reload' + [RESTARTABLE_UNITS]='restart reload-or-restart' [JOBS]='cancel' [SNAPSHOTS]='delete' [ENVS]='set-environment unset-environment' @@ -110,6 +115,10 @@ _systemctl () { comps=$( __filter_units_by_property CanStart yes \ $( __get_inactive_units | grep -Ev '\.(device|snapshot)$' )) + elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then + comps=$( __filter_units_by_property CanStart yes \ + $( __get_all_units | grep -Ev '\.(device|snapshot|socket|timer)$' )) + elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then comps=$( __filter_units_by_property CanStop yes \ $( __get_active_units ) ) @@ -129,13 +138,13 @@ _systemctl () { comps='' elif __contains_word "$verb" ${VERBS[JOBS]}; then - comps=$( systemctl list-jobs | awk '{print $1}' ) + comps=$( __systemctl list-jobs | awk '{print $1}' ) elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then - comps=$( systemctl list-units --type snapshot --full --all | awk '{print $1}' ) + comps=$( __systemctl list-units --type snapshot --full --all | awk '{print $1}' ) elif __contains_word "$verb" ${VERBS[ENVS]}; then - comps=$( systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' ) + comps=$( __systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' ) compopt -o nospace fi