1.1 --- a/scripts/bash_completion.pl Sat Aug 15 16:15:30 2015 +0200
1.2 +++ b/scripts/bash_completion.pl Sun Aug 16 01:25:01 2015 +0200
1.3 @@ -39,11 +39,38 @@
1.4
1.5 my $databasesFile = "$configDir/bash-completion/databases";
1.6 my $formattersFile = "$configDir/bash-completion/formatters";
1.7 +my $formatterPropertiesDir = "$configDir/bash-completion/formatter-properties";
1.8
1.9 print '#have sql-dk &&
1.10 -_sql_dk()
1.11 -{
1.12 - local cur prev
1.13 +_sql_dk_bash_completion_find_formatter() {
1.14 + local previous
1.15 + for token in "$@"; do
1.16 + if [ "x$previous" == "x--formatter" ]; then
1.17 + echo -n "$token";
1.18 + fi
1.19 + previous="$token";
1.20 + done
1.21 +}
1.22 +
1.23 +_sql_dk_bash_completion_formatter_property() {
1.24 + if [ -n "$formatter" ]; then # TODO: this does not match formatter name in apostrophes or quotes
1.25 + local formatter_dir='.$formatterPropertiesDir.'/$formatter
1.26 + if [ -d $formatter_dir ]; then
1.27 + ls -1 $formatter_dir;
1.28 + fi
1.29 + fi
1.30 +}
1.31 +
1.32 +_sql_dk_bash_completion_formatter_property_choice() {
1.33 + local property="${COMP_WORDS[COMP_CWORD-1]}";
1.34 + echo true;
1.35 + echo false;
1.36 + echo "TODO_$property";
1.37 + # TODO: find choices for the property
1.38 +}
1.39 +
1.40 +_sql_dk_bash_completion() {
1.41 + local cur prev formatter
1.42
1.43 COMPREPLY=()
1.44 cur=${COMP_WORDS[COMP_CWORD]}
1.45 @@ -75,7 +102,17 @@
1.46 fi
1.47 return 0
1.48 ;;
1.49 + --formatter-property)
1.50 + formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
1.51 + COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property )" -- $cur ) );
1.52 + return 0;
1.53 + ;;
1.54 esac;
1.55 +
1.56 + if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then
1.57 + COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) );
1.58 + return 0;
1.59 + fi
1.60
1.61 COMPREPLY=( $( compgen -W "
1.62 ';
1.63 @@ -91,5 +128,5 @@
1.64
1.65 }
1.66
1.67 -complete -F _sql_dk sql-dk
1.68 +complete -F _sql_dk_bash_completion sql-dk
1.69 ';