1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

bash-completion: timedatectl: suggests hostname and machine name

This commit is contained in:
Yu Watanabe 2018-01-10 23:03:26 +09:00
parent e352389a02
commit 68c7139a4b

View File

@ -25,16 +25,24 @@ __contains_word () {
done
}
__get_machines() {
local a b
machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
}
_timedatectl() {
local i verb comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local OPTS='-h --help --version --adjust-system-clock --no-pager
--no-ask-password -H --host --machine'
--no-ask-password -H --host -M --machine'
if __contains_word "$prev" $OPTS; then
case $prev in
--host|-H)
comps=''
comps=$(compgen -A hostname)
;;
--machine|-M)
comps=$( __get_machines )
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
@ -48,7 +56,7 @@ _timedatectl() {
local -A VERBS=(
[BOOLEAN]='set-local-rtc set-ntp'
[STANDALONE]='status set-time list-timezones'
[STANDALONE]='status list-timezones'
[TIMEZONES]='set-timezone'
[TIME]='set-time'
)