File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,38 @@ __contains_word () {
2525 done
2626}
2727
28+ __get_machines () {
29+ local a b
30+ machinectl list --full --no-legend --no-pager 2> /dev/null |
31+ { while read a b; do echo " $a " ; done ; };
32+ }
33+
2834_hostnamectl () {
2935 local i verb comps
3036 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
31- local OPTS=' -h --help --version --transient --static --pretty
32- --no-ask-password -H --host -M --machine'
37+ local -A OPTS=(
38+ [STANDALONE]=' -h --help --version --transient --static --pretty --no-ask-password'
39+ [ARG]=' -H --host -M --machine --json'
40+ )
41+
42+ if __contains_word " $prev " ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]} ; then
43+ case $prev in
44+ --host|-H)
45+ comps=$( compgen -A hostname)
46+ ;;
47+ --machine|-M)
48+ comps=$( __get_machines )
49+ ;;
50+ --json)
51+ comps=$( hostnamectl --json=help 2> /dev/null )
52+ ;;
53+ * )
54+ return 0
55+ ;;
56+ esac
57+ COMPREPLY=( $( compgen -W ' $comps' -- " $cur " ) )
58+ return 0
59+ fi
3360
3461 if [[ $cur = -* ]]; then
3562 COMPREPLY=( $( compgen -W ' ${OPTS[*]}' -- " $cur " ) )
Original file line number Diff line number Diff line change @@ -75,6 +75,13 @@ _hostnamectl_commands() {
7575 fi
7676}
7777
78+ (( $+ functions[_hostnamectl_get_json] )) || _hostnamectl_get_json ()
79+ {
80+ local -a _json_forms
81+ _json_forms=( $( hostnamectl --json=help 2> /dev/null) )
82+ _values ' format' $_json_forms
83+ }
84+
7885_arguments -s \
7986 {-h,--help}' [Show this help]' \
8087 ' --version[Show package version]' \
@@ -84,4 +91,5 @@ _arguments -s \
8491 ' --no-ask-password[Do not prompt for password]' \
8592 {-H+,--host=}' [Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
8693 {-M+,--machine=}' [Operate on local container]:machines:_sd_machines' \
94+ ' --json[Shows output formatted as JSON]:format:_hostnamectl_get_json' \
8795 ' *::hostnamectl commands:_hostnamectl_commands'
You can’t perform that action at this time.
0 commit comments