Modernize bash-completion

Use _init_completion
Support long options with or without =
Auto generate options from the --help using _parse_help
This commit is contained in:
Nirgal Vourgère
2020-10-27 00:05:26 +01:00
parent 58f240ac6f
commit 9e50c7401d
12 changed files with 93 additions and 157 deletions

View File

@@ -1,26 +1,20 @@
#-*- mode: shell-script;-*-
_mdb_schema()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
local cur prev words cword split
_init_completion -s || return
if [[ "$prev" == -@(T|-table|N|-namespace) ]] ; then
return 0
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-T --table \
-N --namespace \
--drop-table --no-drop-table \
--not-null --no-not-null \
--default-values --no-default-values \
--not-empty --no-not-empty \
--indexes --no-indexes \
--relations --no-relations
-h --help' -- $cur ) )
fi
$split && return
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
[[ $COMPREPLY == *= ]] && compopt -o nospace
elif [[ "$prev" == @(*mdb|*mdw|*accdb) ]]; then
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql' -- $cur ) )
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- "$cur" ) )
else
_filedir '@(mdb|mdw|accdb)'
fi