Add simple bash_completion script
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
parent
5548cbc865
commit
7669f9c1ef
2
Makefile
2
Makefile
@ -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
50
bash_completion
Normal 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
|
Loading…
Reference in New Issue
Block a user