1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/sql-dk/bash-completion.sh Fri Dec 27 17:51:05 2013 +0100
1.3 @@ -0,0 +1,8 @@
1.4 +#!/bin/bash
1.5 +
1.6 +cat \
1.7 + src/info/globalcode/sql/dk/Constants.java \
1.8 + src/info/globalcode/sql/dk/formatting/* \
1.9 + src/info/globalcode/sql/dk/CLIParser.java \
1.10 + | ../../scripts/bash_completion.pl
1.11 +
2.1 --- a/java/sql-dk/build.xml Fri Dec 27 17:40:27 2013 +0100
2.2 +++ b/java/sql-dk/build.xml Fri Dec 27 17:51:05 2013 +0100
2.3 @@ -76,4 +76,8 @@
2.4 <exec executable="./version-info.sh" output="data/info/globalcode/sql/dk/version.txt"/>
2.5 </target>
2.6
2.7 + <target name="-post-jar">
2.8 + <exec executable="./bash-completion.sh" output="dist/bash-completion.sh"/>
2.9 + </target>
2.10 +
2.11 </project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/scripts/bash_completion.pl Fri Dec 27 17:51:05 2013 +0100
3.3 @@ -0,0 +1,68 @@
3.4 +#!/usr/bin/perl
3.5 +
3.6 +# Parses Java source code from STDIN and generates script for BASH completion
3.7 +# Input (in this order):
3.8 +# info/globalcode/sql/dk/Constants.java
3.9 +# info/globalcode/sql/dk/formatting/*
3.10 +# info/globalcode/sql/dk/CLIParser.java
3.11 +
3.12 +use strict;
3.13 +use warnings;
3.14 +
3.15 +my $configDir = "~";
3.16 +
3.17 +while (<>) {
3.18 + if (/"(.*?)".*? \/\/\s*bash-completion:dir/) {
3.19 + $configDir .= "/$1";
3.20 + last;
3.21 + }
3.22 +}
3.23 +
3.24 +print 'have sql-dk &&
3.25 +_sql_dk()
3.26 +{
3.27 + local cur prev
3.28 +
3.29 + COMPREPLY=()
3.30 + cur=${COMP_WORDS[COMP_CWORD]}
3.31 + prev=${COMP_WORDS[COMP_CWORD-1]}
3.32 +
3.33 + case "$prev" in
3.34 + --db)
3.35 + COMPREPLY=( $( echo "TODO_DATABASE_NAMES" ) );
3.36 + # ' . $configDir .'
3.37 + return 0
3.38 + ;;
3.39 + --formatter)
3.40 + COMPREPLY=( $( compgen -W "
3.41 +';
3.42 +
3.43 +while (<>) {
3.44 + if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
3.45 + print " $1\n";
3.46 + }
3.47 + last if (/\/\/\s*bash-completion:options/);
3.48 +}
3.49 +
3.50 +
3.51 +print ' " -- $cur ) );
3.52 + return 0
3.53 + ;;
3.54 + esac;
3.55 +
3.56 + COMPREPLY=( $( compgen -W "
3.57 +';
3.58 +
3.59 +while (<>) {
3.60 + if (/"(.*?)".*? \/\/\s*bash-completion:option/) {
3.61 + print " $1\n";
3.62 + }
3.63 +}
3.64 +
3.65 +print ' " -- $cur ) )
3.66 + return 0
3.67 +
3.68 +}
3.69 +
3.70 +complete -F _sql_dk sql-dk
3.71 +';