scripts/bash_completion.pl
author František Kučera <franta-hg@frantovo.cz>
Wed, 15 Jan 2014 22:22:45 +0100
branchv_0
changeset 163 1df10a9be6f4
parent 159 9632b23df30c
child 209 8dfe037b3274
permissions -rwxr-xr-x
XML formatter: fix null column values
     1 #!/usr/bin/perl
     2 
     3 # SQL-DK
     4 # Copyright © 2013 František Kučera (frantovo.cz)
     5 # 
     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.
    10 # 
    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.
    15 # 
    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/>.
    18 
    19 
    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
    25 
    26 # TODO: support database/formatter names with spaces
    27 
    28 use strict;
    29 use warnings;
    30 
    31 my $configDir = "~";
    32 
    33 while (<>) {
    34 	if (/"(.*?)".*? \/\/\s*bash-completion:dir/) {
    35 		$configDir .= "/$1";
    36 		last;
    37 	}
    38 }
    39 
    40 my $databasesFile  = "$configDir/bash-completion/databases";
    41 my $formattersFile = "$configDir/bash-completion/formatters";
    42 
    43 print '#have sql-dk &&
    44 _sql_dk()
    45 {
    46 	local cur prev
    47 
    48 	COMPREPLY=()
    49 	cur=${COMP_WORDS[COMP_CWORD]}
    50 	prev=${COMP_WORDS[COMP_CWORD-1]}
    51 
    52 	case "$prev" in
    53 	--db | --test-connection | --list-jdbc-properties)
    54 		if [ -f '.$databasesFile.' ]; then
    55 			COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) )
    56 			return 0
    57 		fi
    58 		;;
    59 	--formatter)
    60 		if [ -f '.$formattersFile.' ]; then
    61 			COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
    62 		else
    63 			COMPREPLY=( $( compgen -W "
    64 ';
    65 
    66 while (<>) {
    67 	if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
    68 		print "				$1\n";
    69 	}
    70 	last if (/\/\/\s*bash-completion:options/);
    71 }
    72 
    73 
    74 print '				" -- $cur ) );
    75 		fi
    76 		return 0
    77 		;;
    78 	esac;
    79 
    80 	COMPREPLY=( $( compgen -W "
    81 ';
    82 
    83 while (<>) {
    84 	if (/"(.*?)".*? \/\/\s*bash-completion:option/) {
    85 		print "			$1\n";
    86 	}
    87 }
    88 
    89 print '		" -- $cur ) )
    90 	return 0
    91 
    92 }
    93 
    94 complete -F _sql_dk sql-dk
    95 ';