4 # Copyright © 2013 František Kučera (frantovo.cz)
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Parses Java source code from STDIN and generates script for BASH completion
21 # Input (in this order):
22 # info/globalcode/sql/dk/Constants.java
23 # info/globalcode/sql/dk/formatting/*
24 # info/globalcode/sql/dk/CLIParser.java
26 # TODO: support database/formatter names with spaces
34 if (/"(.*?)".*? \/\/\s*bash-completion:dir/) {
40 my $databasesFile = "$configDir/bash-completion/databases";
41 my $formattersFile = "$configDir/bash-completion/formatters";
42 my $formatterPropertiesDir = "$configDir/bash-completion/formatter-properties";
44 print '#have sql-dk &&
45 _sql_dk_bash_completion_find_formatter() {
48 if [ "x$previous" == "x--formatter" ]; then
55 _sql_dk_bash_completion_formatter_property() {
56 if [ -n "$formatter" ]; then # TODO: this does not match formatter name in apostrophes or quotes
57 local formatter_dir='.$formatterPropertiesDir.'/$formatter
58 if [ -d $formatter_dir ]; then
64 _sql_dk_bash_completion_formatter_property_choice() {
65 local property="${COMP_WORDS[COMP_CWORD-1]}";
66 local formatter_dir='.$formatterPropertiesDir.'/$formatter
67 local property_choices_file=$formatter_dir/$property/choices;
68 if [ -f $property_choices_file ]; then
69 cat $property_choices_file;
73 _sql_dk_bash_completion() {
74 local cur prev formatter
77 cur=${COMP_WORDS[COMP_CWORD]}
78 prev=${COMP_WORDS[COMP_CWORD-1]}
81 --db | --test-connection | --list-jdbc-properties)
82 if [ -f '.$databasesFile.' ]; then
83 COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) )
87 --formatter | --list-formatter-properties)
88 if [ -f '.$formattersFile.' ]; then
89 COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
91 COMPREPLY=( $( compgen -W "
95 if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
98 last if (/\/\/\s*bash-completion:options/);
102 print ' " -- $cur ) );
106 --formatter-property)
107 formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
108 COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property )" -- $cur ) );
113 if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then
114 formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
115 COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) );
119 COMPREPLY=( $( compgen -W "
123 if (/"(.*?)".*? \/\/\s*bash-completion:option/) {
128 print ' " -- $cur ) )
133 complete -F _sql_dk_bash_completion sql-dk