3
3
# "Duncan Coutts" <
[email protected] >
4
4
#
5
5
6
+ # List cabal targets by type, pass:
7
+ # - test-suite for test suites
8
+ # - benchmark for benchmarks
9
+ # - executable for executables
10
+ # - executable|test-suite|benchmark for the three
11
+ _cabal_list()
12
+ {
13
+ cat *.cabal |
14
+ grep -Ei "^[[:space:]]*($1)[[:space:]]" |
15
+ sed -e "s/.* \([^ ]*\).*/\1/"
16
+ }
17
+
18
+ # List possible targets depending on the command supplied as parameter. The
19
+ # ideal option would be to implement this via --list-options on cabal directly.
20
+ # This is a temporary workaround.
21
+ _cabal_targets()
22
+ {
23
+ # If command ($*) contains build, repl, test or bench completes with
24
+ # targets of according type.
25
+ [ -f *.cabal ] || return 0
26
+ local comp
27
+ for comp in $*; do
28
+ [ $comp == build ] && _cabal_list "executable|test-suite|benchmark" && break
29
+ [ $comp == repl ] && _cabal_list "executable|test-suite|benchmark" && break
30
+ [ $comp == run ] && _cabal_list "executable" && break
31
+ [ $comp == test ] && _cabal_list "test-suite" && break
32
+ [ $comp == bench ] && _cabal_list "benchmark" && break
33
+ done
34
+ }
35
+
6
36
_cabal()
7
37
{
8
38
# get the word currently being completed
@@ -18,7 +48,7 @@ _cabal()
18
48
cmd[${COMP_CWORD}]="--list-options"
19
49
20
50
# the resulting completions should be put into this array
21
- COMPREPLY=( $( compgen -W "$( ${cmd[@]} )" -- $cur ) )
51
+ COMPREPLY=( $( compgen -W "$( ${cmd[@]} ) $( _cabal_targets ${cmd[@]} ) " -- $cur ) )
22
52
}
23
53
24
54
complete -F _cabal -o default cabal
0 commit comments