bash completion: use dynamic completion derived from configuration if available v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 27 Dec 2013 18:16:45 +0100
branchv_0
changeset 82adea6d8d3708
parent 81 847c83288d01
child 83 9563232ea0b7
bash completion: use dynamic completion derived from configuration if available
scripts/bash_completion.pl
     1.1 --- a/scripts/bash_completion.pl	Fri Dec 27 17:51:05 2013 +0100
     1.2 +++ b/scripts/bash_completion.pl	Fri Dec 27 18:16:45 2013 +0100
     1.3 @@ -6,6 +6,8 @@
     1.4  #	info/globalcode/sql/dk/formatting/*
     1.5  #	info/globalcode/sql/dk/CLIParser.java
     1.6  
     1.7 +# TODO: support database/formatter names with spaces
     1.8 +
     1.9  use strict;
    1.10  use warnings;
    1.11  
    1.12 @@ -18,6 +20,9 @@
    1.13  	}
    1.14  }
    1.15  
    1.16 +my $databasesFile  = "$configDir/bash-completion/databases";
    1.17 +my $formattersFile = "$configDir/bash-completion/formatters";
    1.18 +
    1.19  print 'have sql-dk &&
    1.20  _sql_dk()
    1.21  {
    1.22 @@ -29,23 +34,28 @@
    1.23  
    1.24  	case "$prev" in
    1.25  	--db)
    1.26 -		COMPREPLY=( $( echo "TODO_DATABASE_NAMES" ) );
    1.27 -		# ' . $configDir .'
    1.28 -		return 0
    1.29 +		if [ -f '.$databasesFile.' ]; then
    1.30 +			COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) )
    1.31 +			return 0
    1.32 +		fi
    1.33  		;;
    1.34  	--formatter)
    1.35 -		COMPREPLY=( $( compgen -W "
    1.36 +		if [ -f '.$formattersFile.' ]; then
    1.37 +			COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
    1.38 +		else
    1.39 +			COMPREPLY=( $( compgen -W "
    1.40  ';
    1.41  
    1.42  while (<>) {
    1.43  	if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) {
    1.44 -		print "			$1\n";
    1.45 +		print "				$1\n";
    1.46  	}
    1.47  	last if (/\/\/\s*bash-completion:options/);
    1.48  }
    1.49  
    1.50  
    1.51 -print '			" -- $cur ) );
    1.52 +print '				" -- $cur ) );
    1.53 +		fi
    1.54  		return 0
    1.55  		;;
    1.56  	esac;