equal
deleted
inserted
replaced
3 # Parses Java source code from STDIN and generates script for BASH completion |
3 # Parses Java source code from STDIN and generates script for BASH completion |
4 # Input (in this order): |
4 # Input (in this order): |
5 # info/globalcode/sql/dk/Constants.java |
5 # info/globalcode/sql/dk/Constants.java |
6 # info/globalcode/sql/dk/formatting/* |
6 # info/globalcode/sql/dk/formatting/* |
7 # info/globalcode/sql/dk/CLIParser.java |
7 # info/globalcode/sql/dk/CLIParser.java |
|
8 |
|
9 # TODO: support database/formatter names with spaces |
8 |
10 |
9 use strict; |
11 use strict; |
10 use warnings; |
12 use warnings; |
11 |
13 |
12 my $configDir = "~"; |
14 my $configDir = "~"; |
16 $configDir .= "/$1"; |
18 $configDir .= "/$1"; |
17 last; |
19 last; |
18 } |
20 } |
19 } |
21 } |
20 |
22 |
|
23 my $databasesFile = "$configDir/bash-completion/databases"; |
|
24 my $formattersFile = "$configDir/bash-completion/formatters"; |
|
25 |
21 print 'have sql-dk && |
26 print 'have sql-dk && |
22 _sql_dk() |
27 _sql_dk() |
23 { |
28 { |
24 local cur prev |
29 local cur prev |
25 |
30 |
27 cur=${COMP_WORDS[COMP_CWORD]} |
32 cur=${COMP_WORDS[COMP_CWORD]} |
28 prev=${COMP_WORDS[COMP_CWORD-1]} |
33 prev=${COMP_WORDS[COMP_CWORD-1]} |
29 |
34 |
30 case "$prev" in |
35 case "$prev" in |
31 --db) |
36 --db) |
32 COMPREPLY=( $( echo "TODO_DATABASE_NAMES" ) ); |
37 if [ -f '.$databasesFile.' ]; then |
33 # ' . $configDir .' |
38 COMPREPLY=( $( compgen -W " $( cat '.$databasesFile.' ) " -- $cur ) ) |
34 return 0 |
39 return 0 |
|
40 fi |
35 ;; |
41 ;; |
36 --formatter) |
42 --formatter) |
37 COMPREPLY=( $( compgen -W " |
43 if [ -f '.$formattersFile.' ]; then |
|
44 COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) ) |
|
45 else |
|
46 COMPREPLY=( $( compgen -W " |
38 '; |
47 '; |
39 |
48 |
40 while (<>) { |
49 while (<>) { |
41 if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) { |
50 if (/"(.*?)".*? \/\/\s*bash-completion:formatter/) { |
42 print " $1\n"; |
51 print " $1\n"; |
43 } |
52 } |
44 last if (/\/\/\s*bash-completion:options/); |
53 last if (/\/\/\s*bash-completion:options/); |
45 } |
54 } |
46 |
55 |
47 |
56 |
48 print ' " -- $cur ) ); |
57 print ' " -- $cur ) ); |
|
58 fi |
49 return 0 |
59 return 0 |
50 ;; |
60 ;; |
51 esac; |
61 esac; |
52 |
62 |
53 COMPREPLY=( $( compgen -W " |
63 COMPREPLY=( $( compgen -W " |