Permalink
Switch branches/tags
ghc-7.6.3-release ghc-7.6.2-release ghc-7.6.1-release dist/cabal-install-v1.20.0.6 checkpoint cabal-install_merged cabal-install-v1.24.0.2 cabal-install-v1.24.0.1 cabal-install-v1.24.0.0 cabal-install-v1.22.9.0 cabal-install-v1.22.8.0 cabal-install-v1.22.7.0 cabal-install-v1.22.6.0 cabal-install-v1.22.5.0 cabal-install-v1.22.4.0 cabal-install-v1.22.3.0 cabal-install-v1.22.2.0 cabal-install-v1.22.0.1 cabal-install-v1.22.0.0 cabal-install-v1.22.0.0-rc cabal-install-v1.20.2.0 cabal-install-v1.20.1.0 cabal-install-v1.20.0.5 cabal-install-v1.20.0.4 cabal-install-v1.20.0.4-rc cabal-install-v1.20.0.3 cabal-install-v1.20.0.2 cabal-install-v1.20.0.1 cabal-install-v1.20.0.0 cabal-install-v1.20.0.0-rc2 cabal-install-v1.20.0-rc cabal-install-v1.18.2.0 cabal-install-v1.18.1.0 cabal-install-v1.18.0.8 cabal-install-v1.18.0.7 cabal-install-v1.18.0.6 cabal-install-v1.18.0.6-rc cabal-install-v1.18.0.5 cabal-install-v1.18.0.4 cabal-install-v1.18.0.3 cabal-install-v1.18.0.2 cabal-install-v1.18.0.1 cabal-install-v1.18.0 cabal-install-v1.16.1.0 cabal-install-v1.16.0.2 cabal-install-v1.16.0.1 cabal-install-v.1.16.0 cabal-install-v1.16.0 cabal-install-v0.14.1 cabal-install-0.14.0 GHC_6_12_3_release GHC_6_12_2_release GHC_6_8_3_release Cabal_1_8_0_6_release Cabal_1_8_0_2_release Cabal-v2.0.0.2 Cabal-v2.0.0.1 Cabal-v2.0.0.0 Cabal-v1.24.2.0 Cabal-v1.24.1.0 Cabal-v1.24.0.0 Cabal-v1.22.8.0 Cabal-v1.22.7.0 Cabal-v1.22.6.0 Cabal-v1.22.5.0 Cabal-v1.22.4.0 Cabal-v1.22.3.0 Cabal-v1.22.2.0 Cabal-v1.22.1.1 Cabal-v1.22.1.0 Cabal-v1.22.0.0 Cabal-v1.22.0.0-rc Cabal-v1.20.0.4 Cabal-v1.20.0.3 Cabal-v1.20.0.3-rc Cabal-v1.20.0.2 Cabal-v1.20.0.1 Cabal-v1.20.0.0 Cabal-v1.20.0.0-rc Cabal-v1.20.0-rc Cabal-v1.18.1.6 Cabal-v1.18.1.5 Cabal-v1.18.1.5-rc Cabal-v1.18.1.4 Cabal-v1.18.1.3 Cabal-v1.18.1.2 Cabal-v1.18.1.1 Cabal-v1.18.1 Cabal-v1.18.0 Cabal-v1.16.0.3 Cabal-v1.16.0.2 Cabal-v1.16.0.1 Cabal-v1.16.0 Cabal-1.20.0.0-release Cabal-1.18.1.3-release Cabal-1.18.1.2-release Cabal-1.18.1.1-release Cabal-1.18.1-release Cabal-1.18.0-release 2008-06-06
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
95 lines (84 sloc) 3.01 KB
# cabal command line completion
# Copyright 2007-2008 "Lennart Kolmodin" <kolmodin@gentoo.org>
# "Duncan Coutts" <dcoutts@gentoo.org>
#
# 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()
{
for f in ./*.cabal; do
grep -Ei "^[[:space:]]*($1)[[:space:]]" "$f" |
sed -e "s/.* \([^ ]*\).*/\1/"
done
}
# 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.
local comp
for comp in "$@"; do
[ "$comp" == new-build ] && _cabal_list "executable|test-suite|benchmark" && break
[ "$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
}
# List possible subcommands of a cabal subcommand.
#
# In example "sandbox" is a cabal subcommand that itself has subcommands. Since
# "cabal --list-options" doesn't work in such cases we have to get the list
# using other means.
_cabal_subcommands()
{
local word
for word in "$@"; do
case "$word" in
sandbox)
# Get list of "cabal sandbox" subcommands from its help message.
"$1" help sandbox |
sed -n '1,/^Subcommands:$/d;/^Flags for sandbox:$/,$d;/^ /d;s/^\(.*\):/\1/p'
break # Terminate for loop.
;;
esac
done
}
__cabal_has_doubledash ()
{
local c=1
# Ignore the last word, because it is replaced anyways.
# This allows expansion for flags on "cabal foo --",
# but does not try to complete after "cabal foo -- ".
local n=$((${#COMP_WORDS[@]} - 1))
while [ $c -lt $n ]; do
if [ "--" = "${COMP_WORDS[c]}" ]; then
return 0
fi
((c++))
done
return 1
}
_cabal()
{
# no completion past cabal arguments.
__cabal_has_doubledash && return
# get the word currently being completed
local cur
cur=${COMP_WORDS[$COMP_CWORD]}
# create a command line to run
local cmd
# copy all words the user has entered
cmd=( ${COMP_WORDS[@]} )
# replace the current word with --list-options
cmd[${COMP_CWORD}]="--list-options"
# the resulting completions should be put into this array
COMPREPLY=( $( compgen -W "$( eval "${cmd[@]}" 2>/dev/null ) $( _cabal_targets "${cmd[@]}" ) $( _cabal_subcommands "${COMP_WORDS[@]}" )" -- "$cur" ) )
}
complete -F _cabal -o default cabal