scripts/bash_completion.pl
author František Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 09:40:22 +0200
branchv_0
changeset 203 504c4ba56d1c
parent 159 9632b23df30c
child 209 8dfe037b3274
permissions -rwxr-xr-x
connection tunnelling: configuration and logging
franta-hg@81
     1
#!/usr/bin/perl
franta-hg@81
     2
franta-hg@83
     3
# SQL-DK
franta-hg@83
     4
# Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@83
     5
# 
franta-hg@83
     6
# This program is free software: you can redistribute it and/or modify
franta-hg@83
     7
# it under the terms of the GNU General Public License as published by
franta-hg@83
     8
# the Free Software Foundation, either version 3 of the License, or
franta-hg@83
     9
# (at your option) any later version.
franta-hg@83
    10
# 
franta-hg@83
    11
# This program is distributed in the hope that it will be useful,
franta-hg@83
    12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@83
    13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@83
    14
# GNU General Public License for more details.
franta-hg@83
    15
# 
franta-hg@83
    16
# You should have received a copy of the GNU General Public License
franta-hg@83
    17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@83
    18
franta-hg@83
    19
franta-hg@81
    20
# Parses Java source code from STDIN and generates script for BASH completion
franta-hg@81
    21
# Input (in this order):
franta-hg@81
    22
#	info/globalcode/sql/dk/Constants.java
franta-hg@81
    23
#	info/globalcode/sql/dk/formatting/*
franta-hg@81
    24
#	info/globalcode/sql/dk/CLIParser.java
franta-hg@81
    25
franta-hg@82
    26
# TODO: support database/formatter names with spaces
franta-hg@82
    27
franta-hg@81
    28
use strict;
franta-hg@81
    29
use warnings;
franta-hg@81
    30
franta-hg@81
    31
my $configDir = "~";
franta-hg@81
    32
franta-hg@81
    33
while (<>) {
franta-hg@81
    34
	if (/"(.*?)".*? \/\/\s*bash-completion:dir/) {
franta-hg@81
    35
		$configDir .= "/$1";
franta-hg@81
    36
		last;
franta-hg@81
    37
	}
franta-hg@81
    38
}
franta-hg@81
    39
franta-hg@82
    40
my $databasesFile  = "$configDir/bash-completion/databases";
franta-hg@82
    41
my $formattersFile = "$configDir/bash-completion/formatters";
franta-hg@82
    42
franta-hg@110
    43
print '#have sql-dk &&
franta-hg@81
    44
_sql_dk()
franta-hg@81
    45
{
franta-hg@81
    46
	local cur prev
franta-hg@81
    47
franta-hg@81
    48
	COMPREPLY=()
franta-hg@81
    49
	cur=${COMP_WORDS[COMP_CWORD]}
franta-hg@81
    50
	prev=${COMP_WORDS[COMP_CWORD-1]}
franta-hg@81
    51
franta-hg@81
    52
	case "$prev" in
franta-hg@159
    53
	--db | --test-connection | --list-jdbc-properties)
franta-hg@82
    54
		if [ -f '.$databasesFile.' ]; then
franta-hg@82
    55
			COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) )
franta-hg@82
    56
			return 0
franta-hg@82
    57
		fi
franta-hg@81
    58
		;;
franta-hg@81
    59
	--formatter)
franta-hg@82
    60
		if [ -f '.$formattersFile.' ]; then
franta-hg@82
    61
			COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
franta-hg@82
    62
		else
franta-hg@82
    63
			COMPREPLY=( $( compgen -W "
franta-hg@81
    64
';
franta-hg@81
    65
franta-hg@81
    66
while (<>) {
franta-hg@81
    67
	if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
franta-hg@82
    68
		print "				$1\n";
franta-hg@81
    69
	}
franta-hg@81
    70
	last if (/\/\/\s*bash-completion:options/);
franta-hg@81
    71
}
franta-hg@81
    72
franta-hg@81
    73
franta-hg@82
    74
print '				" -- $cur ) );
franta-hg@82
    75
		fi
franta-hg@81
    76
		return 0
franta-hg@81
    77
		;;
franta-hg@81
    78
	esac;
franta-hg@81
    79
franta-hg@81
    80
	COMPREPLY=( $( compgen -W "
franta-hg@81
    81
';
franta-hg@81
    82
franta-hg@81
    83
while (<>) {
franta-hg@81
    84
	if (/"(.*?)".*? \/\/\s*bash-completion:option/) {
franta-hg@81
    85
		print "			$1\n";
franta-hg@81
    86
	}
franta-hg@81
    87
}
franta-hg@81
    88
franta-hg@81
    89
print '		" -- $cur ) )
franta-hg@81
    90
	return 0
franta-hg@81
    91
franta-hg@81
    92
}
franta-hg@81
    93
franta-hg@81
    94
complete -F _sql_dk sql-dk
franta-hg@81
    95
';