diff -r 3b1733fb3793 -r 0bc544b38cfa scripts/bash_completion.pl --- a/scripts/bash_completion.pl Sat Aug 15 16:15:30 2015 +0200 +++ b/scripts/bash_completion.pl Sun Aug 16 01:25:01 2015 +0200 @@ -39,11 +39,38 @@ my $databasesFile = "$configDir/bash-completion/databases"; my $formattersFile = "$configDir/bash-completion/formatters"; +my $formatterPropertiesDir = "$configDir/bash-completion/formatter-properties"; print '#have sql-dk && -_sql_dk() -{ - local cur prev +_sql_dk_bash_completion_find_formatter() { + local previous + for token in "$@"; do + if [ "x$previous" == "x--formatter" ]; then + echo -n "$token"; + fi + previous="$token"; + done +} + +_sql_dk_bash_completion_formatter_property() { + if [ -n "$formatter" ]; then # TODO: this does not match formatter name in apostrophes or quotes + local formatter_dir='.$formatterPropertiesDir.'/$formatter + if [ -d $formatter_dir ]; then + ls -1 $formatter_dir; + fi + fi +} + +_sql_dk_bash_completion_formatter_property_choice() { + local property="${COMP_WORDS[COMP_CWORD-1]}"; + echo true; + echo false; + echo "TODO_$property"; + # TODO: find choices for the property +} + +_sql_dk_bash_completion() { + local cur prev formatter COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} @@ -75,7 +102,17 @@ fi return 0 ;; + --formatter-property) + formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" ); + COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property )" -- $cur ) ); + return 0; + ;; esac; + + if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then + COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) ); + return 0; + fi COMPREPLY=( $( compgen -W " '; @@ -91,5 +128,5 @@ } -complete -F _sql_dk sql-dk +complete -F _sql_dk_bash_completion sql-dk ';