From: Dave Reisner Date: Sat, 20 Oct 2012 21:48:11 +0000 (-0400) Subject: bash-completion: add completions for hostnamectl X-Git-Tag: v195~25 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=26be51de330e544ade97a9345bbfa60d5674cb7a;ds=sidebyside bash-completion: add completions for hostnamectl --- diff --git a/bash-completion/systemd-bash-completion.sh b/bash-completion/systemd-bash-completion.sh index 636c80031..1a7df5764 100644 --- a/bash-completion/systemd-bash-completion.sh +++ b/bash-completion/systemd-bash-completion.sh @@ -439,3 +439,38 @@ _localectl() { return 0 } complete -F _localectl localectl + +_hostnamectl() { + local verb comps + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local OPTS='-h --help --version --transient --static --pretty + --no-ask-password -H --host' + + if [[ $cur = -* ]]; then + COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) + return 0 + fi + + local -A VERBS=( + [STANDALONE]='status' + [ICONS]='set-icon-name' + [NAME]='set-hostname' + ) + + for ((i=0; i <= COMP_CWORD; i++)); do + if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then + verb=${COMP_WORDS[i]} + break + fi + done + + if [[ -z $verb ]]; then + comps=${VERBS[*]} + elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then + comps='' + fi + + COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) + return 0 +} +complete -F _hostnamectl hostnamectl