r1034 - /trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager
zack at users.alioth.debian.org
zack at users.alioth.debian.org
Mon Sep 24 08:25:09 UTC 2007
Author: zack
Date: Mon Sep 24 08:25:09 2007
New Revision: 1034
URL: http://svn.debian.org/wsvn/pkg-vim/?sc=1&rev=1034
Log:
update bash completion to the latest version provided by Antonio
Modified:
trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager
Modified: trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager
URL: http://svn.debian.org/wsvn/pkg-vim/trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager?rev=1034&op=diff
==============================================================================
--- trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager (original)
+++ trunk/packages/vim-addon-manager/etc/bash_completion.d/vim-addon-manager Mon Sep 24 08:25:09 2007
@@ -1,11 +1,10 @@
-# vim-addons completion script for vim-addons
+# vim-addon-manager: completion script for vim-addons
#
# Copyright (c) 2007, Antonio Terceiro <terceiro at softwarelivre.org>
#
# This program is free software, you can redistribute it and/or modify it under
-# the terms of the GNU General Public License version 2 as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
+# the terms of the GNU General Public License version 3, or (at your option)
+# any later version published by the Free Software Foundation.
_complete_vim_addons() {
@@ -14,7 +13,16 @@
prev=${COMP_WORDS[COMP_CWORD-1]}
commands="list status install remove disable amend files show"
- options="-h --help -r --registry-dir -s --source-dir -t --target-dir -v --verbose -y --system-dir -w --system-wide"
+ any_command=$(echo $commands | sed -e 's/\s\+/|/g')
+
+ options="-h --help -r --registry-dir -s --source-dir -t --target-dir -v --verbose -y --system-dir -w --system-wide -q --query"
+ any_option=$(echo $options | sed -e 's/\s\+/|/g')
+
+ # complete commands
+ if [[ "$prev" == 'vim-addons' ]]; then
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ return 0
+ fi
# complete option names
if [[ "$cur" == -* ]]; then
@@ -22,30 +30,74 @@
return 0
fi
- case "$prev" in
+ # complete directory name for some options
+ if [[ "$prev" == @(-r|--registry-dir|-s|--source-dir|-t|--target-dir|-y|--system-dir) ]]; then
+ COMPREPLY=( $( compgen -o dirnames -- $cur ) )
+ return 0
+ fi
- # complete commands
- vim-addons)
- COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
- return 0
+ command=''
+ target_dir=''
+ system_wide=''
+ system_dir=''
+ for (( i=0; i < ${#COMP_WORDS[@]}-1; i++)); do
+
+ # check for command
+ if [[ ${COMP_WORDS[i]} == @($any_command) ]]; then
+ command=${COMP_WORDS[i]}
+ fi
+
+ # check for -w or --system-wide
+ if [[ ${COMP_WORDS[i]} == @(-w|--system-wide) ]]; then
+ system_wide="--system-wide"
+ fi
+
+ if [[ $i -gt 0 ]]; then
+ # check for -t or --target-dir
+ if [[ ${COMP_WORDS[i-1]} == @(-t|--target-dir) ]]; then
+ target_dir="--target-dir ${COMP_WORDS[i]}"
+ fi
+
+ # check for -y or --system-dir
+ if [[ ${COMP_WORDS[i-1]} == @(-y|--system-dir) ]]; then
+ system_dir="--system-dir ${COMP_WORDS[i]}"
+ fi
+ fi
+
+ done
+
+ # build the query command
+ query="vim-addons status --query $system_wide $system_dir $target_dir"
+
+ # no command, cannot know how to complete
+ if [[ -z "$command" ]]; then
+ COMPREPLY=()
+ return 0;
+ fi
+
+ case "$command" in
+ # no addon names if command is 'list'
+ list)
+ COMPREPLY=()
;;
- # complete directory names
- -r|--registry-dir|-s|--source-dir|-t|--target-dir|-y|--system-dir)
- COMPREPLY=( $( compgen -o dirnames -- $cur ) )
- return 0
+ # list only non-installed addons
+ install)
+ COMPREPLY=( $( $query | grep -e "^$cur" | grep -v -e "installed$" | sed -e 's/^\(\S\+\).*/\1/' ) )
+ ;;
+
+ # list only installed addons
+ remove|disable|amend)
+ COMPREPLY=( $( $query | grep -e "^$cur" | grep -e "installed$" | sed -e 's/^\(\S\+\).*/\1/' ) )
;;
# complete addon names
*)
COMPREPLY=($(grep -h "^addon: $cur" /usr/share/vim/registry/*.yaml | sed -e 's/^addon:\s*//'))
-
- return 0
;;
esac
-
}
-
complete -F _complete_vim_addons -o default vim-addons
+# vim: sw=2 expandtab ft=sh
More information about the pkg-vim-maintainers
mailing list