Skip to content

Commit a2a9eca

Browse files
committed
Merge pull request #1932 from rudymatela/master
Included targets in cabal's bash-completion.
2 parents 430cc97 + d8c113e commit a2a9eca

File tree

1 file changed

+31
-1
lines changed
  • cabal-install/bash-completion

1 file changed

+31
-1
lines changed

cabal-install/bash-completion/cabal

+31-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@
33
# "Duncan Coutts" <[email protected]>
44
#
55

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+
636
_cabal()
737
{
838
# get the word currently being completed
@@ -18,7 +48,7 @@ _cabal()
1848
cmd[${COMP_CWORD}]="--list-options"
1949

2050
# the resulting completions should be put into this array
21-
COMPREPLY=( $( compgen -W "$( ${cmd[@]} )" -- $cur ) )
51+
COMPREPLY=( $( compgen -W "$( ${cmd[@]} ) $( _cabal_targets ${cmd[@]} )" -- $cur ) )
2252
}
2353

2454
complete -F _cabal -o default cabal

0 commit comments

Comments
 (0)