tabular formatter: new option 'separateBy' to print horizontal separator on each change of given column
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, version 3 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Parses Java source code from STDIN and generates script for BASH completion
20 # Input (in this order):
21 # info/globalcode/sql/dk/Constants.java
22 # info/globalcode/sql/dk/formatting/*
23 # info/globalcode/sql/dk/CLIParser.java
25 # TODO: support database/formatter names with spaces
33 if (/"(.*?)".*? \/\/\s*bash-completion:dir/) {
39 my $databasesFile = "$configDir/bash-completion/databases";
40 my $formattersFile = "$configDir/bash-completion/formatters";
41 my $defaultFormatterFile = "$configDir/bash-completion/default-formatter";
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 if [ -f '.$defaultFormatterFile.' ]; then
56 cat '.$defaultFormatterFile.'
60 _sql_dk_bash_completion_formatter_property_name() {
61 if [ -n "$formatter" ]; then # TODO: this does not match formatter name in apostrophes or quotes
62 local formatter_dir='.$formatterPropertiesDir.'/$formatter
63 if [ -d $formatter_dir ]; then
69 _sql_dk_bash_completion_formatter_property_choice() {
70 local property="${COMP_WORDS[COMP_CWORD-1]}";
71 local formatter_dir='.$formatterPropertiesDir.'/$formatter
72 local property_choices_file=$formatter_dir/$property/choices;
73 if [ -f $property_choices_file ]; then
74 cat $property_choices_file;
78 _sql_dk_bash_completion() {
79 local cur prev formatter
82 cur=${COMP_WORDS[COMP_CWORD]}
83 prev=${COMP_WORDS[COMP_CWORD-1]}
86 --db | --test-connection | --list-jdbc-properties)
87 if [ -f '.$databasesFile.' ]; then
88 COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) )
92 --formatter | --list-formatter-properties)
93 if [ -f '.$formattersFile.' ]; then
94 COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
96 COMPREPLY=( $( compgen -W "
100 if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
103 last if (/\/\/\s*bash-completion:options/);
107 print ' " -- $cur ) );
111 --formatter-property)
112 formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
113 COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_name )" -- $cur ) );
118 if [ "x${COMP_WORDS[COMP_CWORD-2]}" == "x--formatter-property" ]; then
119 formatter=$( _sql_dk_bash_completion_find_formatter "${COMP_WORDS[@]}" );
120 COMPREPLY=( $( compgen -W "$(_sql_dk_bash_completion_formatter_property_choice )" -- $cur ) );
124 COMPREPLY=( $( compgen -W "
128 if (/"(.*?)".*? \/\/\s*bash-completion:option/) {
133 print ' " -- $cur ) )
138 complete -F _sql_dk_bash_completion sql-dk