Skip to content

Included targets in cabal's bash-completion. #1932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion cabal-install/bash-completion/cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
# "Duncan Coutts" <[email protected]>
#

# List cabal targets by type, pass:
# - test-suite for test suites
# - benchmark for benchmarks
# - executable for executables
# - executable|test-suite|benchmark for the three
_cabal_list()
{
cat *.cabal |
grep -Ei "^[[:space:]]*($1)[[:space:]]" |
sed -e "s/.* \([^ ]*\).*/\1/"
}

# List possible targets depending on the command supplied as parameter. The
# ideal option would be to implement this via --list-options on cabal directly.
# This is a temporary workaround.
_cabal_targets()
{
# If command ($*) contains build, repl, test or bench completes with
# targets of according type.
[ -f *.cabal ] || return 0
local comp
for comp in $*; do
[ $comp == build ] && _cabal_list "executable|test-suite|benchmark" && break
[ $comp == repl ] && _cabal_list "executable|test-suite|benchmark" && break
[ $comp == run ] && _cabal_list "executable" && break
[ $comp == test ] && _cabal_list "test-suite" && break
[ $comp == bench ] && _cabal_list "benchmark" && break
done
}

_cabal()
{
# get the word currently being completed
Expand All @@ -18,7 +48,7 @@ _cabal()
cmd[${COMP_CWORD}]="--list-options"

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

complete -F _cabal -o default cabal