mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-02-26 22:02:43 +08:00
Use _init_completion Support long options with or without = Auto generate options from the --help using _parse_help
31 lines
740 B
Bash
31 lines
740 B
Bash
#-*- mode: shell-script;-*-
|
|
_mdb_import()
|
|
{
|
|
local cur prev words cword split
|
|
_init_completion -s || return
|
|
|
|
if [[ "$prev" == -@(H|--header|d|-delimiter) ]]; then
|
|
return 0
|
|
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
|
|
dbname=$prev
|
|
__expand_tilde_by_ref dbname
|
|
local IFS=$'\n'
|
|
tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
|
|
compopt -o filenames
|
|
COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
|
|
else
|
|
_filedir '@(mdb|mdw|accdb|txt|csv)'
|
|
fi
|
|
return 0
|
|
} &&
|
|
complete -F _mdb_import mdb-import
|