1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00

bash-completion: add completions for hostnamectl

This commit is contained in:
Dave Reisner 2012-10-20 17:48:11 -04:00
parent 0962e09ec3
commit 26be51de33

View File

@ -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