summaryrefslogtreecommitdiffstats
path: root/shell-completion/bash
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-12-13 17:26:52 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-13 17:26:52 +0100
commita73b2f4ab34c58c9fcd44a7787a7543d87978180 (patch)
tree9b047b2c452b6c3607401a03c4ca3b30cccdf5d4 /shell-completion/bash
parentbash-completion: bootctl: suggest argument for --path option (diff)
downloadsystemd-a73b2f4ab34c58c9fcd44a7787a7543d87978180.tar.xz
systemd-a73b2f4ab34c58c9fcd44a7787a7543d87978180.zip
bash-completion: bootctl: support set-default and set-oneshot
Diffstat (limited to 'shell-completion/bash')
-rw-r--r--shell-completion/bash/bootctl20
1 files changed, 20 insertions, 0 deletions
diff --git a/shell-completion/bash/bootctl b/shell-completion/bash/bootctl
index 648103fbc0..64bff4f879 100644
--- a/shell-completion/bash/bootctl
+++ b/shell-completion/bash/bootctl
@@ -24,6 +24,10 @@ __contains_word () {
done
}
+__get_entry_ids() {
+ bootctl --no-pager list 2>/dev/null | { while read -r a b; do [[ $a == 'id:' ]] && echo " $b"; done }
+}
+
_bootctl() {
local i verb comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
@@ -54,6 +58,7 @@ _bootctl() {
local -A VERBS=(
[STANDALONE]='help install list remove status update'
+ [BOOTENTRY]='set-default set-oneshot'
)
for ((i=0; i < COMP_CWORD; i++)); do
@@ -67,6 +72,21 @@ _bootctl() {
comps=${VERBS[*]}
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
comps=''
+ elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then
+ name=
+ for ((i++; i < COMP_CWORD; i++)); do
+ if ! __contains_word "${COMP_WORDS[i]}" ${OPTS[*]} ${VERBS[*]} &&
+ ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
+ name=${COMP_WORDS[i]}
+ break;
+ fi
+ done
+
+ if [[ -z $name ]]; then
+ comps=$( __get_entry_ids )
+ else
+ comps=''
+ fi
fi
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )