From 50c84aab4dbd2f050f40fb97fc857d7632382ae9 Mon Sep 17 00:00:00 2001 From: Cary Robbins Date: Thu, 14 Aug 2014 00:09:33 -0500 Subject: [PATCH] Updated cabal completion to leverage standard bash approach. Updated sandbox info. --- plugins/cabal/cabal.plugin.zsh | 59 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/plugins/cabal/cabal.plugin.zsh b/plugins/cabal/cabal.plugin.zsh index 9f76add7a..90a5f4811 100644 --- a/plugins/cabal/cabal.plugin.zsh +++ b/plugins/cabal/cabal.plugin.zsh @@ -2,46 +2,37 @@ function cabal_sandbox_info() { cabal_files=(*.cabal(N)) if [ $#cabal_files -gt 0 ]; then if [ -f cabal.sandbox.config ]; then - echo "%{$fg[green]%}sandboxed%{$reset_color%}" + echo "%{$fg[green]%}[sandboxed] %{$reset_color%}" else - echo "%{$fg[red]%}not sandboxed%{$reset_color%}" + echo "%{$fg[red]%}[not sandboxed] %{$reset_color%}" fi fi } -function _cabal_commands() { - local ret=1 state - _arguments ':subcommand:->subcommand' && ret=0 +autoload bashcompinit +bashcompinit - case $state in - subcommand) - subcommands=( - "bench:Run the benchmark, if any (configure with UserHooks)" - "build:Make this package ready for installation" - "check:Check the package for common mistakes" - "clean:Clean up after a build" - "copy:Copy teh files into the install locations" - "configure:Prepare to build the package" - "fetch:Downloads packages for later installation" - "haddock:Generate HAddock HTML documentation" - "help:Help about commands" - "hscolour:Generate HsColour colourised code, in HTML format" - "info:Display detailed information about a particular package" - "init:Interactively create a .cabal file" - "install:Installs a list of packages" - "list:List packages matching a search string" - "register:Register this package with the compiler" - "report:Upload build reports to a remote server" - "sdist:Generate a source distribution file (.tar.gz)" - "test:Run the test suite, if any (configure with UserHooks)" - "unpack:Unpacks packages for user inspection" - "update:Updates list of known packages" - "upload:Uploads source packages to Hackage" - ) - _describe -t subcommands 'cabal subcommands' subcommands && ret=0 - esac +# cabal command line completion +# Copyright 2007-2008 "Lennart Kolmodin" +# "Duncan Coutts" +# - return ret +_cabal() +{ + # 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 "$( ${cmd[@]} )" -- $cur ) ) } -compdef _cabal_commands cabal +complete -F _cabal -o default cabal