mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-18 09:50:07 +08:00
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:
@@ -1,26 +1,18 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_count()
|
||||
{
|
||||
local cur prev
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
if [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then
|
||||
local dbname
|
||||
local tablenames
|
||||
local tablename
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
tablenames=""
|
||||
while read tablename
|
||||
do
|
||||
#shell-quote each line
|
||||
tablenames="$tablenames"$'\n'"$(printf %q "${tablename}")"
|
||||
done < <(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)
|
||||
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -1,40 +1,31 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_export()
|
||||
{
|
||||
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" == -@(d|-delimiter|R|-row-delimiter|q|-quote|X|-escape|N|-namespace|S|-batch-size|D|-date-format|T|-datetime-format|0|-null|h|-help) ]] ; then
|
||||
return 0
|
||||
elif [[ "$prev" == -@(I|-insert) ]] ; then
|
||||
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- "$cur" ) )
|
||||
elif [[ "$prev" == -@(b|-bin) ]] ; then
|
||||
COMPREPLY=( $( compgen -W 'strip raw octal hex' -- $cur ) )
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-H -d -R -Q -q -X -I -N -S -D -T -0 -B -h \
|
||||
--no-header --delimiter --row-delimiter \
|
||||
--no-quote --quote --escape \
|
||||
--insert --namespace --batch-size \
|
||||
--date-format --datetime-format \
|
||||
--null --bin --boolean-words
|
||||
--help' -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W 'strip raw octal hex' -- "$cur" ) )
|
||||
fi
|
||||
|
||||
$split && return
|
||||
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||
elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then
|
||||
local dbname
|
||||
local tablenames
|
||||
local tablename
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
tablenames=""
|
||||
while read tablename
|
||||
do
|
||||
#shell-quote each line
|
||||
tablenames="$tablenames"$'\n'"$(printf %q "${tablename}")"
|
||||
done < <(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)
|
||||
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_hexdump()
|
||||
{
|
||||
local cur
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
if (( COMP_CWORD == 1 )); then
|
||||
if (( $cword == 1 )); then
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
return 0
|
||||
|
@@ -1,33 +1,27 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_import()
|
||||
{
|
||||
local cur
|
||||
local cur prev words cword split
|
||||
_init_completion -s || return
|
||||
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
if [[ "$prev" == -@(d|-delimiter) ]]; then
|
||||
if [[ "$prev" == -@(H|--header|d|-delimiter) ]]; then
|
||||
return 0
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-H --header \
|
||||
-d --delimiter \
|
||||
-h --help' -- $cur ) )
|
||||
fi
|
||||
|
||||
$split && return
|
||||
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '--header= --delimiter= --help' -- "$cur" ) )
|
||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||
elif [[ "$prev" == @(*mdb|*mdw|*accdb) ]]; then
|
||||
local dbname
|
||||
local tablenames
|
||||
local tablename
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
tablenames=""
|
||||
while read tablename
|
||||
do
|
||||
#shell-quote each line
|
||||
tablenames="$tablenames"$'\n'"$(printf %q "${tablename}")"
|
||||
done < <(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)
|
||||
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb|txt|csv)'
|
||||
fi
|
||||
|
@@ -1,33 +1,27 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_json()
|
||||
{
|
||||
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" == -@(D|-date-format|T|-datetime-format|U|--no-unprintable|h|-help) ]] ; then
|
||||
return 0
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-h -D -T -U \
|
||||
--date-format --datetime-format \
|
||||
--no-unprintable \
|
||||
--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
|
||||
local dbname
|
||||
local tablenames
|
||||
local tablename
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
tablenames=""
|
||||
while read tablename
|
||||
do
|
||||
#shell-quote each line
|
||||
tablenames="$tablenames"$'\n'"$(printf %q "${tablename}")"
|
||||
done < <(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)
|
||||
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -1,11 +1,10 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_parsecsv()
|
||||
{
|
||||
local cur
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
if (( COMP_CWORD == 1 )); then
|
||||
if (( $cword == 1 )); then
|
||||
_filedir '@(txt|csv)'
|
||||
fi
|
||||
return 0
|
||||
|
@@ -1,30 +1,22 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_prop()
|
||||
{
|
||||
local cur
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
|
||||
if (( COMP_CWORD == 1 )); then
|
||||
if (( $cword == 1 )); then
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
elif (( COMP_CWORD == 2 )); then
|
||||
elif (( $cword == 2 )); then
|
||||
local dbname
|
||||
local tablenames
|
||||
local tablename
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
tablenames=""
|
||||
while read tablename
|
||||
do
|
||||
#shell-quote each line
|
||||
tablenames="$tablenames"$'\n'"$(printf %q "${tablename}")"
|
||||
done < <(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)
|
||||
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) )
|
||||
elif (( COMP_CWORD == 3 )); then
|
||||
COMPREPLY=( $( compgen -W 'Lv LvProp LvModule LvExtra' -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
||||
elif (( $cword == 3 )); then
|
||||
COMPREPLY=( $( compgen -W 'Lv LvProp LvModule LvExtra' -- "$cur" ) )
|
||||
fi
|
||||
return 0
|
||||
} &&
|
||||
|
@@ -1,33 +1,22 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_queries()
|
||||
{
|
||||
local cur prev
|
||||
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
if [[ "$prev" == -@(d) ]]; then
|
||||
return 0
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-L\
|
||||
-1 \
|
||||
-d' -- $cur ) )
|
||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||
elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then
|
||||
local dbname
|
||||
local querynames
|
||||
local queryname
|
||||
dbname=$prev
|
||||
__expand_tilde_by_ref dbname
|
||||
local IFS=$'\n'
|
||||
querynames=""
|
||||
while read queryname
|
||||
do
|
||||
#shell-quote each line
|
||||
querynames="$querynames"$'\n'"$(printf %q "${queryname}")"
|
||||
done < <(eval mdb-queries -1 "${dbname}" 2>/dev/null)
|
||||
querynames="$(eval mdb-queries -1 "${dbname}" 2>/dev/null)"
|
||||
compopt -o filenames
|
||||
COMPREPLY=( $( compgen -W "${querynames}" -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W "${querynames}" -- "$cur" ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -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
|
||||
|
@@ -1,24 +1,20 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_sql()
|
||||
{
|
||||
local cur prev
|
||||
local cur prev words cword split
|
||||
_init_completion -s || return
|
||||
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
if [[ "$prev" == -d ]] ; then
|
||||
if [[ "$prev" == -@(P|-no-pretty-print|H|-no-header|F|-no-footer) ]] ; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
$split && return
|
||||
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||
elif [[ "$prev" == -@(i|-input|o|-output) ]] ; then
|
||||
_filedir
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-H --no-header \
|
||||
-F --no-footer \
|
||||
-p --no-pretty-print \
|
||||
-d --delimiter \
|
||||
-i --input \
|
||||
-o --output \
|
||||
-h --help' -- $cur ) )
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -1,24 +1,21 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_tables()
|
||||
{
|
||||
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" == -@(d|-delimiter) ]]; then
|
||||
return 0
|
||||
elif [[ "$prev" == -@(t|-type) ]]; then
|
||||
COMPREPLY=( $( compgen -W 'form table macro systable report query linkedtable module relationship dbprop any all' -- $cur ) )
|
||||
COMPREPLY=( $( compgen -W 'form table macro systable report query linkedtable module relationship dbprop any all' -- "$cur" ) )
|
||||
return 0
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-S --system\
|
||||
-1 --single-column \
|
||||
-d --delimiter \
|
||||
-t --type \
|
||||
-T --showtype \
|
||||
-h --help' -- $cur ) )
|
||||
fi
|
||||
|
||||
$split && return
|
||||
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
@@ -1,13 +1,12 @@
|
||||
#-*- mode: shell-script;-*-
|
||||
_mdb_ver()
|
||||
{
|
||||
local cur
|
||||
|
||||
COMPREPLY=()
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local cur prev words cword
|
||||
_init_completion || return
|
||||
|
||||
if [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W '-M -h --help' -- $cur ) )
|
||||
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
|
||||
#COMPREPLY=($(compgen -W '--help --mdbtools' -- "$cur"))
|
||||
else
|
||||
_filedir '@(mdb|mdw|accdb)'
|
||||
fi
|
||||
|
Reference in New Issue
Block a user