Add simple bash_completion script

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
Виталий Чикунов 2022-10-05 05:06:12 +03:00
parent 5548cbc865
commit 7669f9c1ef
2 changed files with 52 additions and 0 deletions

View File

@ -2,7 +2,9 @@ check:
bash -n update-kernel
bash -n remove-old-kernels
bash -n analyze-kmodules
bash -n bash_completion
shellcheck -x update-kernel remove-old-kernels analyze-kmodules
shellcheck -s bash bash_completion
docker-build:
docker build .

50
bash_completion Normal file
View File

@ -0,0 +1,50 @@
# bash completion for update-kernel -*- shell-script -*-
# shellcheck disable=SC2207,SC2155
_update_kernel()
{
# shellcheck disable=SC2034
local cur prev words cword
_init_completion || return
local cmd=${1##*/}
case $prev in
-t | --type)
# shellcheck disable=SC2034
local flavours="
ovz-el7
std-def
std-kvm
un-def
"
COMPREPLY=( $(compgen -W "\$flavours" -- "$cur" | sort ) )
return
;;
-A)
return
;;
-r | --release)
return
;;
esac
if [[ $cur == -* ]]; then
local script="/usr/sbin/$cmd"
if [ -f "$script" ]; then
local short=$(LC_ALL=C grep -oP 'getopt.*-o \K[^\s]+' "$script" | sed -E 's/://g; s/(^|,)/\n-/g')
local long=$(LC_ALL=C grep -oP 'getopt.*-l \K[^\s]+' "$script" | sed -E 's/://g; s/(^|,)/\n--/g')
# shellcheck disable=SC2034
local opts=$(LC_ALL=C echo "$short $long" | sort)
COMPREPLY=($( compgen -W "\$opts" -- "$cur") )
else
# Fallback
COMPREPLY=($( compgen -W "\$(_parse_help $1)" -- "$cur") )
fi
fi
} &&
complete -F _update_kernel update-kernel remove-old-kernels
# ex: filetype=sh sw=4 et