From 8ed22786aaca0e28da8af66ccc2aaafe6071bf68 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 14 Dec 2018 01:25:31 +0900 Subject: [PATCH 1/3] bash-completion: bootctl: add one missing option --- shell-completion/bash/bootctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell-completion/bash/bootctl b/shell-completion/bash/bootctl index e24d113219..f45e3e2a97 100644 --- a/shell-completion/bash/bootctl +++ b/shell-completion/bash/bootctl @@ -28,7 +28,7 @@ _bootctl() { local i verb comps local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} local -A OPTS=( - [STANDALONE]='-h --help --no-variables -p --print-path --version' + [STANDALONE]='-h --help --no-variables -p --print-path --version --no-pager' [ARG]='--path' ) From ed0c5a6f8966ba3a128ec7762f4e33846dfae643 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 14 Dec 2018 01:26:25 +0900 Subject: [PATCH 2/3] bash-completion: bootctl: suggest argument for --path option --- shell-completion/bash/bootctl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shell-completion/bash/bootctl b/shell-completion/bash/bootctl index f45e3e2a97..648103fbc0 100644 --- a/shell-completion/bash/bootctl +++ b/shell-completion/bash/bootctl @@ -32,6 +32,21 @@ _bootctl() { [ARG]='--path' ) + if __contains_word "$prev" ${OPTS[ARG]}; then + case $prev in + --path) + if [[ -z $cur ]]; then + comps=$(compgen -A directory -- "/" ) + else + comps=$(compgen -A directory -- "$cur" ) + fi + compopt -o filenames + ;; + esac + COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) + return 0 + fi + if [[ "$cur" = -* ]]; then COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) return 0 From a73b2f4ab34c58c9fcd44a7787a7543d87978180 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 14 Dec 2018 01:26:52 +0900 Subject: [PATCH 3/3] bash-completion: bootctl: support set-default and set-oneshot --- shell-completion/bash/bootctl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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") )