summaryrefslogtreecommitdiffstats
path: root/shell-completion/bash
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-05-12 18:37:41 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-05-14 02:18:29 +0200
commitf8cd3f610fc0dba38f23c8e2e98bab83f38b4e72 (patch)
tree3afe02fee2e8ea51506a5b493671a7efbbba4169 /shell-completion/bash
parentnetworkctl: introduce --json option for "status" and "list" commands (diff)
downloadsystemd-f8cd3f610fc0dba38f23c8e2e98bab83f38b4e72.tar.xz
systemd-f8cd3f610fc0dba38f23c8e2e98bab83f38b4e72.zip
shell-completion: support --json option for hostnamectl
Diffstat (limited to 'shell-completion/bash')
-rw-r--r--shell-completion/bash/hostnamectl31
1 files changed, 29 insertions, 2 deletions
diff --git a/shell-completion/bash/hostnamectl b/shell-completion/bash/hostnamectl
index 5c8d3975d7..af4339111e 100644
--- a/shell-completion/bash/hostnamectl
+++ b/shell-completion/bash/hostnamectl
@@ -25,11 +25,38 @@ __contains_word () {
done
}
+__get_machines() {
+ local a b
+ machinectl list --full --no-legend --no-pager 2>/dev/null |
+ { while read a b; do echo " $a"; done; };
+}
+
_hostnamectl() {
local i 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 -M --machine'
+ local -A OPTS=(
+ [STANDALONE]='-h --help --version --transient --static --pretty --no-ask-password'
+ [ARG]='-H --host -M --machine --json'
+ )
+
+ if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
+ case $prev in
+ --host|-H)
+ comps=$(compgen -A hostname)
+ ;;
+ --machine|-M)
+ comps=$( __get_machines )
+ ;;
+ --json)
+ comps=$( hostnamectl --json=help 2>/dev/null )
+ ;;
+ *)
+ return 0
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+ fi
if [[ $cur = -* ]]; then
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )