From 5b292e00636449eeb383bb440e6b498f2b27963b Mon Sep 17 00:00:00 2001 From: Rainer Hurling Date: Sat, 24 Oct 2020 20:29:46 +0200 Subject: [PATCH 1/8] Unsigned error in index.c On FreeBSD 13.0-CURRENT its compiler clang-11.0.0 complains: index.c:388:14: error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare] for (i=0; i Date: Sat, 24 Oct 2020 20:07:21 +0000 Subject: [PATCH 2/8] Spelling typo --- doc/mdb-queries.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mdb-queries.txt b/doc/mdb-queries.txt index c6b82c6..7787a03 100644 --- a/doc/mdb-queries.txt +++ b/doc/mdb-queries.txt @@ -12,7 +12,7 @@ DESCRIPTION OPTIONS -L List queries in the database (default if no query name is passed) - -1 Use newline as the delimiter (used in conjuction with listing) + -1 Use newline as the delimiter (used in conjunction with listing) -d delim Specify delimiter to use NOTES From 78c4f12eacb2dc7cdefcee5fda7ba8e6e8aa4efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Sun, 25 Oct 2020 11:21:34 +0100 Subject: [PATCH 3/8] Ignore errors when setting terminal colors --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index f0017d8..1b94215 100644 --- a/configure.ac +++ b/configure.ac @@ -319,10 +319,10 @@ dnl doc/reference/libmdb/Makefile]) ################################################## -bold_red=$(tput bold)$(tput setf 4) -bold_green=$(tput bold)$(tput setf 2) -bold=$(tput bold) -reset=$(tput sgr0) +bold_red=$(tput bold 2>/dev/null)$(tput setf 4 2>/dev/null) +bold_green=$(tput bold 2>/dev/null)$(tput setf 2 2>/dev/null) +bold=$(tput bold 2>/dev/null) +reset=$(tput sgr0 2>/dev/null) AC_MSG_NOTICE([]) AC_MSG_NOTICE([${bold}MDB Tools $VERSION - Configuration summary${reset}]) AC_MSG_NOTICE([]) From ea478f3bc69cf721daa81247ed3ed0da55bf2b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Sun, 25 Oct 2020 11:24:28 +0100 Subject: [PATCH 4/8] mdb-export: reorder options, man, bash-completion --- doc/mdb-export.txt | 20 ++++++++++++++------ src/util/bash-completion/mdb-export | 16 ++++++++++------ src/util/mdb-export.c | 8 ++++---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/doc/mdb-export.txt b/doc/mdb-export.txt index e3072f4..d14fc86 100644 --- a/doc/mdb-export.txt +++ b/doc/mdb-export.txt @@ -2,7 +2,8 @@ NAME mdb-export - Export data in an MDB database table to CSV format. SYNOPSIS - mdb-export [-H] [-d delim] [-R delim] [[-Q] | [-q char [-X char]]] [-I backend] [-D fmt] [-N prefix] [-b strip|raw|octal] database table + mdb-export [--no-header] [--delimiter delim] [--row-delimiter delim] [[--no-quote] | [--quote char [--escape char]]] [--date-format fmt] [--datetime-format fmt] [--bin strip|raw|octal|hex] [--boolean-words] database table + mdb-export --backend backend [--namespace prefix] [--batch-size int] database table mdb-export -h|--help DESCRIPTION @@ -10,19 +11,26 @@ DESCRIPTION It produces a CSV (comma separated value) output for the given table. Such output is suitable for importation into databases or spreadsheets. + Used with --insert, it outputs SQL specific to backend dialect, including some constraints like NOT NULL and foreign keys. + OPTIONS -H, --no-header Suppress header row. - -Q, --no-quote Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters. -d, --delimiter delim Specify an alternative column delimiter. Default is , (comma). -R, --row-delimiter delim Specify a row delimiter. Default is \\n (ASCII value 10). - -I, --insert backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite. - -D, --date-format fmt Set the date format (see strftime(3) for details). - -q, --quote char Use to wrap text-like fields. Default is " (double quote). - -X, --escape char Use to escape quoted characters within a field. Default is doubling. + -Q, --no-quote Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters. + -q, --quote char Use char to wrap text-like fields. Default is " (double quote). + -X, --escape char Use char to escape quoted characters within a field. Default is doubling. + -I, --backend backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite. -N, --namespace prefix Prefix identifiers with prefix. + -S, --batch-size int Size of insert batches on supported platforms. + -D, --date-format fmt Set the date format (see strftime(3) for details. + -T, --datetime-format fmt Set the date/time format (see strftime(3) for details. + -0, --null char Use char to represent a NULL value. -b, --bin strip|raw|octal|hex Binary export mode: strip binaries, export as-is, output \\ooo style octal data or output \\xx style hexadecimal data. + -B, --boolean-words Use TRUE/FALSE in Boolean fields (default is 0/1). NOTES + Most of the formatting options actually also works with --insert. ENVIRONMENT MDB_JET3_CHARSET Defines the charset of the input JET3 (access 97) file. Default is CP1252. See iconv(1). diff --git a/src/util/bash-completion/mdb-export b/src/util/bash-completion/mdb-export index 6f2ddfb..b618590 100644 --- a/src/util/bash-completion/mdb-export +++ b/src/util/bash-completion/mdb-export @@ -6,16 +6,20 @@ _mdb_export() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|q|-quote|X|-escape|D|-date-format|N|-namespace|h|-help) ]] ; then + if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|-quote|X|-escape|N|-namespace|S|-batch-size|D|-date-format|T|-datetime-format|0|-null|h|-help) ]] ; then return 0 elif [[ "$prev" == -I ]] ; then - COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql' -- $cur ) ) + COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- $cur ) ) elif [[ "$prev" == -@(b|-bin) ]] ; then - COMPREPLY=( $( compgen -W 'strip raw octal' -- $cur ) ) + COMPREPLY=( $( compgen -W 'strip raw octal hex' -- $cur ) ) elif [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '-H -d -R -Q -q -X -I -D -N -b -h \ - --no-header --no-quote --delimiter --row-delimiter --insert \ - --date-format --quote --escape --namespace --bin --help' -- $cur ) ) + 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 \ + --backend --namespace --batch-size \ + --date-format --datetime-format \ + --null --bin --boolean-words + --help' -- $cur ) ) elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then local dbname local tablenames diff --git a/src/util/mdb-export.c b/src/util/mdb-export.c index 52befb8..5008bd9 100755 --- a/src/util/mdb-export.c +++ b/src/util/mdb-export.c @@ -54,19 +54,19 @@ main(int argc, char **argv) GOptionEntry entries[] = { {"no-header", 'H', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &header_row, "Suppress header row.", NULL}, - {"no-quote", 'Q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, "e_text, "Don't wrap text-like fields in quotes.", NULL}, {"delimiter", 'd', 0, G_OPTION_ARG_STRING, &delimiter, "Specify an alternative column delimiter. Default is comma.", "char"}, {"row-delimiter", 'R', 0, G_OPTION_ARG_STRING, &row_delimiter, "Specify a row delimiter", "char"}, + {"no-quote", 'Q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, "e_text, "Don't wrap text-like fields in quotes.", NULL}, {"quote", 'q', 0, G_OPTION_ARG_STRING, "e_char, "Use to wrap text-like fields. Default is double quote.", "char"}, + {"escape", 'X', 0, G_OPTION_ARG_STRING, &escape_char, "Use to escape quoted characters within a field. Default is doubling.", "format"}, {"backend", 'I', 0, G_OPTION_ARG_STRING, &insert_dialect, "INSERT statements (instead of CSV)", "backend"}, + {"namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"}, + {"batch-size", 'S', 0, G_OPTION_ARG_INT, &batch_size, "Size of insert batches on supported platforms.", "int"}, {"date-format", 'D', 0, G_OPTION_ARG_STRING, &shortdate_fmt, "Set the date format (see strftime(3) for details)", "format"}, {"datetime-format", 'T', 0, G_OPTION_ARG_STRING, &date_fmt, "Set the date/time format (see strftime(3) for details)", "format"}, - {"escape", 'X', 0, G_OPTION_ARG_STRING, &escape_char, "Use to escape quoted characters within a field. Default is doubling.", "format"}, - {"namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"}, {"null", '0', 0, G_OPTION_ARG_STRING, &null_text, "Use to represent a NULL value", "char"}, {"bin", 'b', 0, G_OPTION_ARG_STRING, &str_bin_mode, "Binary export mode", "strip|raw|octal|hex"}, {"boolean-words", 'B', 0, G_OPTION_ARG_NONE, &boolean_words, "Use TRUE/FALSE in Boolean fields (default is 0/1)", NULL}, - {"batch-size", 'S', 0, G_OPTION_ARG_INT, &batch_size, "Size of insert batches on supported platforms.", "int"}, {NULL}, }; GError *error = NULL; From c7d527fdeb67ee38249bd44610d9058ad708b5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Sun, 25 Oct 2020 11:34:53 +0100 Subject: [PATCH 5/8] mdb-export: Rename --backend into --insert --- doc/mdb-export.txt | 4 ++-- src/util/bash-completion/mdb-export | 4 ++-- src/util/mdb-export.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/mdb-export.txt b/doc/mdb-export.txt index d14fc86..a46502a 100644 --- a/doc/mdb-export.txt +++ b/doc/mdb-export.txt @@ -3,7 +3,7 @@ NAME SYNOPSIS mdb-export [--no-header] [--delimiter delim] [--row-delimiter delim] [[--no-quote] | [--quote char [--escape char]]] [--date-format fmt] [--datetime-format fmt] [--bin strip|raw|octal|hex] [--boolean-words] database table - mdb-export --backend backend [--namespace prefix] [--batch-size int] database table + mdb-export --insert backend [--namespace prefix] [--batch-size int] database table mdb-export -h|--help DESCRIPTION @@ -20,7 +20,7 @@ OPTIONS -Q, --no-quote Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters. -q, --quote char Use char to wrap text-like fields. Default is " (double quote). -X, --escape char Use char to escape quoted characters within a field. Default is doubling. - -I, --backend backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite. + -I, --insert backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres, mysql and sqlite. -N, --namespace prefix Prefix identifiers with prefix. -S, --batch-size int Size of insert batches on supported platforms. -D, --date-format fmt Set the date format (see strftime(3) for details. diff --git a/src/util/bash-completion/mdb-export b/src/util/bash-completion/mdb-export index b618590..b31924b 100644 --- a/src/util/bash-completion/mdb-export +++ b/src/util/bash-completion/mdb-export @@ -8,7 +8,7 @@ _mdb_export() if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|-quote|X|-escape|N|-namespace|S|-batch-size|D|-date-format|T|-datetime-format|0|-null|h|-help) ]] ; then return 0 - elif [[ "$prev" == -I ]] ; then + elif [[ "$prev" == -@(I|-insert) ]] ; then COMPREPLY=( $( compgen -W 'access sybase oracle postgres mysql sqlite' -- $cur ) ) elif [[ "$prev" == -@(b|-bin) ]] ; then COMPREPLY=( $( compgen -W 'strip raw octal hex' -- $cur ) ) @@ -16,7 +16,7 @@ _mdb_export() 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 \ - --backend --namespace --batch-size \ + --insert --namespace --batch-size \ --date-format --datetime-format \ --null --bin --boolean-words --help' -- $cur ) ) diff --git a/src/util/mdb-export.c b/src/util/mdb-export.c index 5008bd9..1732b10 100755 --- a/src/util/mdb-export.c +++ b/src/util/mdb-export.c @@ -59,7 +59,7 @@ main(int argc, char **argv) {"no-quote", 'Q', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, "e_text, "Don't wrap text-like fields in quotes.", NULL}, {"quote", 'q', 0, G_OPTION_ARG_STRING, "e_char, "Use to wrap text-like fields. Default is double quote.", "char"}, {"escape", 'X', 0, G_OPTION_ARG_STRING, &escape_char, "Use to escape quoted characters within a field. Default is doubling.", "format"}, - {"backend", 'I', 0, G_OPTION_ARG_STRING, &insert_dialect, "INSERT statements (instead of CSV)", "backend"}, + {"insert", 'I', 0, G_OPTION_ARG_STRING, &insert_dialect, "INSERT statements (instead of CSV)", "backend"}, {"namespace", 'N', 0, G_OPTION_ARG_STRING, &namespace, "Prefix identifiers with namespace", "namespace"}, {"batch-size", 'S', 0, G_OPTION_ARG_INT, &batch_size, "Size of insert batches on supported platforms.", "int"}, {"date-format", 'D', 0, G_OPTION_ARG_STRING, &shortdate_fmt, "Set the date format (see strftime(3) for details)", "format"}, From f6053aa21172bff750bb403e1549336041e0ec0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Sun, 25 Oct 2020 20:16:47 +0100 Subject: [PATCH 6/8] Quote shell special characters ... ... and add support for mdb-count mdb-json and mdb-queries --- src/util/bash-completion/Makefile.am | 2 +- src/util/bash-completion/mdb-count | 29 ++++++++++++++++++++++ src/util/bash-completion/mdb-export | 12 ++++++++-- src/util/bash-completion/mdb-import | 12 ++++++++-- src/util/bash-completion/mdb-json | 36 ++++++++++++++++++++++++++++ src/util/bash-completion/mdb-prop | 14 ++++++++--- src/util/bash-completion/mdb-queries | 36 ++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 src/util/bash-completion/mdb-count create mode 100644 src/util/bash-completion/mdb-json create mode 100644 src/util/bash-completion/mdb-queries diff --git a/src/util/bash-completion/Makefile.am b/src/util/bash-completion/Makefile.am index 411ec40..682050c 100644 --- a/src/util/bash-completion/Makefile.am +++ b/src/util/bash-completion/Makefile.am @@ -1,4 +1,4 @@ if ENABLE_BASH_COMPLETION bashcompletiondir = $(BASH_COMPLETION_DIR) -dist_bashcompletion_DATA = mdb-export mdb-hexdump mdb-import mdb-parsecsv mdb-prop mdb-schema mdb-sql mdb-tables mdb-ver +dist_bashcompletion_DATA = mdb-count mdb-export mdb-hexdump mdb-import mdb-json mdb-parsecsv mdb-prop mdb-queries mdb-schema mdb-sql mdb-tables mdb-ver endif diff --git a/src/util/bash-completion/mdb-count b/src/util/bash-completion/mdb-count new file mode 100644 index 0000000..1513d6b --- /dev/null +++ b/src/util/bash-completion/mdb-count @@ -0,0 +1,29 @@ +#-*- mode: shell-script;-*- +_mdb_count() +{ + local cur prev + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + 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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) ) + else + _filedir '@(mdb|mdw|accdb)' + fi + return 0 +} && +complete -F _mdb_count mdb-count diff --git a/src/util/bash-completion/mdb-export b/src/util/bash-completion/mdb-export index b31924b..f746cc8 100644 --- a/src/util/bash-completion/mdb-export +++ b/src/util/bash-completion/mdb-export @@ -23,10 +23,18 @@ _mdb_export() elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then local dbname local tablenames + local tablename dbname=$prev __expand_tilde_by_ref dbname - tablenames=$(eval mdb-tables -S -d / "${dbname}" 2>/dev/null) - COMPREPLY=( $( IFS=/ compgen -W "${tablenames}" -- $cur ) ) + 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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) ) else _filedir '@(mdb|mdw|accdb)' fi diff --git a/src/util/bash-completion/mdb-import b/src/util/bash-completion/mdb-import index c8184b7..88b29c4 100644 --- a/src/util/bash-completion/mdb-import +++ b/src/util/bash-completion/mdb-import @@ -16,10 +16,18 @@ _mdb_import() elif [[ "$prev" == @(*mdb|*mdw|*accdb) ]]; then local dbname local tablenames + local tablename dbname=$prev __expand_tilde_by_ref dbname - tablenames=$(eval mdb-tables -S -d / "${dbname}" 2>/dev/null) - COMPREPLY=( $( IFS=/ compgen -W "${tablenames}" -- $cur ) ) + 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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) ) else _filedir '@(mdb|mdw|accdb|txt|csv)' fi diff --git a/src/util/bash-completion/mdb-json b/src/util/bash-completion/mdb-json new file mode 100644 index 0000000..beb201f --- /dev/null +++ b/src/util/bash-completion/mdb-json @@ -0,0 +1,36 @@ +#-*- mode: shell-script;-*- +_mdb_json() +{ + local cur prev + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + 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 ) ) + 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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) ) + else + _filedir '@(mdb|mdw|accdb)' + fi + return 0 +} && +complete -F _mdb_json mdb-json diff --git a/src/util/bash-completion/mdb-prop b/src/util/bash-completion/mdb-prop index 12aece2..4f9d7bf 100644 --- a/src/util/bash-completion/mdb-prop +++ b/src/util/bash-completion/mdb-prop @@ -11,10 +11,18 @@ _mdb_prop() elif (( COMP_CWORD == 2 )); then local dbname local tablenames - dbname=${COMP_WORDS[1]} + local tablename + dbname=$prev __expand_tilde_by_ref dbname - tablenames=$(eval mdb-tables -S -d / "${dbname}" 2>/dev/null) - COMPREPLY=( $( IFS=/ compgen -W "${tablenames}" -- $cur ) ) + 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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${tablenames}" -- $cur ) ) elif (( COMP_CWORD == 3 )); then COMPREPLY=( $( compgen -W 'Lv LvProp LvModule LvExtra' -- $cur ) ) fi diff --git a/src/util/bash-completion/mdb-queries b/src/util/bash-completion/mdb-queries new file mode 100644 index 0000000..1ea920f --- /dev/null +++ b/src/util/bash-completion/mdb-queries @@ -0,0 +1,36 @@ +#-*- mode: shell-script;-*- +_mdb_queries() +{ + local cur prev + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ "$prev" == -@(d) ]]; then + return 0 + elif [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-L\ + -1 \ + -d' -- $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) + compopt -o filenames + COMPREPLY=( $( compgen -W "${querynames}" -- $cur ) ) + else + _filedir '@(mdb|mdw|accdb)' + fi + return 0 +} && +complete -F _mdb_queries mdb-queries From 58f240ac6f78c4d98302921a89b79252a40e3f8e Mon Sep 17 00:00:00 2001 From: nirgal Date: Sun, 25 Oct 2020 20:49:20 +0000 Subject: [PATCH 7/8] Added back -q support --- src/util/bash-completion/mdb-export | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/bash-completion/mdb-export b/src/util/bash-completion/mdb-export index f746cc8..ba8ba40 100644 --- a/src/util/bash-completion/mdb-export +++ b/src/util/bash-completion/mdb-export @@ -6,7 +6,7 @@ _mdb_export() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - if [[ "$prev" == -@(d|-delimiter|R|-row-delimiter|-quote|X|-escape|N|-namespace|S|-batch-size|D|-date-format|T|-datetime-format|0|-null|h|-help) ]] ; then + 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 ) ) From 9e50c7401d5185df2d03db6d709cea0ade0143d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Tue, 27 Oct 2020 00:05:26 +0100 Subject: [PATCH 8/8] Modernize bash-completion Use _init_completion Support long options with or without = Auto generate options from the --help using _parse_help --- src/util/bash-completion/mdb-count | 16 +++--------- src/util/bash-completion/mdb-export | 35 ++++++++++----------------- src/util/bash-completion/mdb-hexdump | 7 +++--- src/util/bash-completion/mdb-import | 30 +++++++++-------------- src/util/bash-completion/mdb-json | 28 +++++++++------------ src/util/bash-completion/mdb-parsecsv | 7 +++--- src/util/bash-completion/mdb-prop | 24 ++++++------------ src/util/bash-completion/mdb-queries | 21 ++++------------ src/util/bash-completion/mdb-schema | 26 ++++++++------------ src/util/bash-completion/mdb-sql | 24 ++++++++---------- src/util/bash-completion/mdb-tables | 23 ++++++++---------- src/util/bash-completion/mdb-ver | 9 +++---- 12 files changed, 93 insertions(+), 157 deletions(-) diff --git a/src/util/bash-completion/mdb-count b/src/util/bash-completion/mdb-count index 1513d6b..848413b 100644 --- a/src/util/bash-completion/mdb-count +++ b/src/util/bash-completion/mdb-count @@ -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 diff --git a/src/util/bash-completion/mdb-export b/src/util/bash-completion/mdb-export index ba8ba40..7a41482 100644 --- a/src/util/bash-completion/mdb-export +++ b/src/util/bash-completion/mdb-export @@ -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 diff --git a/src/util/bash-completion/mdb-hexdump b/src/util/bash-completion/mdb-hexdump index 13d5d43..d13a3b8 100644 --- a/src/util/bash-completion/mdb-hexdump +++ b/src/util/bash-completion/mdb-hexdump @@ -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 diff --git a/src/util/bash-completion/mdb-import b/src/util/bash-completion/mdb-import index 88b29c4..733dea6 100644 --- a/src/util/bash-completion/mdb-import +++ b/src/util/bash-completion/mdb-import @@ -1,33 +1,27 @@ #-*- mode: shell-script;-*- _mdb_import() { - local cur - - 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 + 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 diff --git a/src/util/bash-completion/mdb-json b/src/util/bash-completion/mdb-json index beb201f..d2e7b35 100644 --- a/src/util/bash-completion/mdb-json +++ b/src/util/bash-completion/mdb-json @@ -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 diff --git a/src/util/bash-completion/mdb-parsecsv b/src/util/bash-completion/mdb-parsecsv index 5e7eb28..5a24fb3 100644 --- a/src/util/bash-completion/mdb-parsecsv +++ b/src/util/bash-completion/mdb-parsecsv @@ -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 diff --git a/src/util/bash-completion/mdb-prop b/src/util/bash-completion/mdb-prop index 4f9d7bf..951559f 100644 --- a/src/util/bash-completion/mdb-prop +++ b/src/util/bash-completion/mdb-prop @@ -1,30 +1,22 @@ #-*- mode: shell-script;-*- _mdb_prop() { - 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)' - 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 } && diff --git a/src/util/bash-completion/mdb-queries b/src/util/bash-completion/mdb-queries index 1ea920f..fd14a43 100644 --- a/src/util/bash-completion/mdb-queries +++ b/src/util/bash-completion/mdb-queries @@ -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 diff --git a/src/util/bash-completion/mdb-schema b/src/util/bash-completion/mdb-schema index 8f90ce1..123ff7c 100644 --- a/src/util/bash-completion/mdb-schema +++ b/src/util/bash-completion/mdb-schema @@ -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 diff --git a/src/util/bash-completion/mdb-sql b/src/util/bash-completion/mdb-sql index 2063fac..a3cc420 100644 --- a/src/util/bash-completion/mdb-sql +++ b/src/util/bash-completion/mdb-sql @@ -1,24 +1,20 @@ #-*- mode: shell-script;-*- _mdb_sql() { - 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 ]] ; 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 diff --git a/src/util/bash-completion/mdb-tables b/src/util/bash-completion/mdb-tables index 5057a3b..1cb608a 100644 --- a/src/util/bash-completion/mdb-tables +++ b/src/util/bash-completion/mdb-tables @@ -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 diff --git a/src/util/bash-completion/mdb-ver b/src/util/bash-completion/mdb-ver index 7b614c2..b67bf89 100644 --- a/src/util/bash-completion/mdb-ver +++ b/src/util/bash-completion/mdb-ver @@ -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