mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
Merge pull request #11145 from yuwata/bash-completion-bootctl
bash-completion: bootctl: support set-default and set-oneshot
This commit is contained in:
@@ -24,14 +24,33 @@ __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]}
|
||||
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'
|
||||
)
|
||||
|
||||
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
|
||||
@@ -39,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
|
||||
@@ -52,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") )
|
||||
|
||||
Reference in New Issue
Block a user