Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal On branch : master
http://hackage.haskell.org/trac/ghc/changeset/ea28e251038709cf36bb88861d4364de438a6b37 >--------------------------------------------------------------- commit ea28e251038709cf36bb88861d4364de438a6b37 Author: Duncan Coutts <[email protected]> Date: Sun Oct 10 20:41:58 2010 +0000 Simplify the bash command completion Fixes #741. Patch contributed by Jan Braun <[email protected]> >--------------------------------------------------------------- cabal-install/bash-completion/cabal | 107 ----------------------------------- 1 files changed, 0 insertions(+), 107 deletions(-) diff --git a/cabal-install/bash-completion/cabal b/cabal-install/bash-completion/cabal index 1f0a563..8ebfabc 100644 --- a/cabal-install/bash-completion/cabal +++ b/cabal-install/bash-completion/cabal @@ -3,70 +3,6 @@ # "Duncan Coutts" <[email protected]> # -# returns packages from cabal list -# usage: _cabal_packages [packages] [versions] [installed] -_cabal_packages() -{ - local packages=no # print package names with versions? ie. foo - local versions=no # print packages and versions? ie. foo-0.42 - local installed=no # only print installed packages? - - while [[ -n "$1" ]]; do - case "$1" in - packages) - packages=yes ;; - versions) - versions=yes ;; - installed) - installed=yes ;; - esac - shift - done - - if [[ "$packages" == "no" && "$versions" == "no" ]]; then - # nothing to print - # set sensible default, print only packages - packages=yes - fi - - local cmd="cabal list --simple-output" - if [[ "$installed" == "yes" ]]; then - cmd="$cmd --installed" - fi - - # save 'cabal list' output to a temporary file - # putting it in a variable would mess up the lines - local tmp=$( mktemp /tmp/cabal_completion.XXXXXX ) - $cmd > $tmp - - if [[ "$packages" == "yes" ]]; then - # print only the names - cat "$tmp" | cut -d' ' -f1 | uniq - fi - - if [[ "$versions" == "yes" ]]; then - # join the name and the version with a dash - cat "$tmp" | sed -e "s: :-:" - fi - - rm -f "$tmp" -} - -_cabal_commands() -{ - # this is already quite fast, and caching does not give a speedup - # 3-4ms - for word in $( cabal --list-options ); do - case $word in - -*) - # ignore flags - continue;; - *) - echo $word ;; - esac - done -} - _cabal() { # get the word currently being completed @@ -78,54 +14,11 @@ _cabal() # copy all words the user has entered cmd=( ${COMP_WORDS[@]} ) - # the word currently beeing completed - local ccword - ccword=cmd[${COMP_CWORD}] - # replace the current word with --list-options cmd[${COMP_CWORD}]="--list-options" - # find the action being completed - local action="unknown" - for cword in ${COMP_WORDS[*]}; do - for act in $( _cabal_commands ); do - if [[ "$cword" == "$act" ]]; then - action=$act - fi - done - done - - # if non empty, we will pass this to _cabal_packages and add the result - # to the completing words - local complete_packages - for cword in ${COMP_WORDS[*]}; do - case $cword in - --installed) - # the user is interested only in installed packages - complete_packages="$complete_packages installed" - esac - done - - case $action in - install|list|upgrade|fetch) - if [[ "$cword" != -* ]]; then - # don't complete with packages if the user is trying to - # complete a flag - complete_packages="$complete_packages packages" - if [[ "$cword" == *- ]]; then - # if the user tries to complete with a version, help by - # completing them too - complete_packages="$complete_packages versions" - fi - fi ;; - esac - # the resulting completions should be put into this array COMPREPLY=( $( compgen -W "$( ${cmd[@]} )" -- $cur ) ) - - if [[ -n "$complete_packages" ]]; then - COMPREPLY+=( $( compgen -W "$( _cabal_packages $complete_packages )" -- $cur ) ) - fi } complete -F _cabal -o default cabal _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
