Bug#440843: vim-addon-manager: add bash completion for vim-addons
Antonio Terceiro
terceiro at softwarelivre.org
Mon Sep 10 14:42:43 UTC 2007
Stefano Zacchiroli escreveu isso aí:
> On Tue, Sep 04, 2007 at 03:28:11PM -0300, Antonio Terceiro wrote:
> > Please consider adding the bash completion script in this message. The
> > attached patch was made against the current state of vim-addon-manager
> > subversion repository.
>
> Thanks, I was indeed considering doing one by myself but never got the
> time to write it down :)
>
> I'll surely add it to the next upload of the package, but I've some
> comments / requests:
> - I've changed (not yet committed though) the license of
> vim-addon-manager to GPL v3 or above, do you mind changing the license
> of your completion script accordingly? It won't be a big deal to have
> both licenses in the package, but I would prefer to have uniformity
> ...
No problem at all, changed.
> - I've changed a bit the packaging part of your patch, mainly to install
> as /etc/bash_completion.d/vim-addon-manager to match package name
> rather than executable name
> - feature requests (nothing strongly required, but which would be pretty
> handy I think):
> 1) after "install" only list addons which are not in the "installed"
> state; after "remove" only list addons which are not in the
> "removed" state and so on ...
> 2) after "list" do not complete addon names
> If you're interested in adding support for (1) I can add a "-q" option
> (for "query" or "quiet") which when passed to status will only show
> the status wrt the current target directory and output it in a more
> easily parsable way (e.g. "name <TAB> status"). At that point the
> completion will just invoke something like "vim-addon -q status" and
> grep for the appropriate statuses. Just let me know if you want to
> work on that (I can do the "vim-addons" part)
Done. The current implementation makes a workaround to check installed
and non-installed addons, and searches for the presence or absence of
the "installed" string in the output of $(vim-addons status). When
such a query mode is implemented in vim-addons I can rework that part.
New version attached.
Cheers,
--
Antonio Terceiro <terceiro at softwarelivre.org>
http://people.softwarelivre.org/~terceiro/
GnuPG ID: 0F9CB28F
-------------- next part --------------
# 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 3, or (at your option)
# any later version published by the Free Software Foundation.
_complete_vim_addons() {
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
commands="list status install remove disable amend files show"
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"
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
COMPREPLY=( $( compgen -W "$options" -- $cur) )
return 0
fi
# 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
command=''
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++)); do
if [[ ${COMP_WORDS[i]} == @($any_command) ]]; then
command=${COMP_WORDS[i]}
fi
done
# 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=()
;;
# list only non-installed addons
install)
COMPREPLY=( $( vim-addons status | grep "$cur" | grep -v '^#' | grep -v installed | sed -e 's/^\(\S\+\).*/\1/' ) )
;;
# list only installed addons
remove|disable|amend)
COMPREPLY=( $( vim-addons status | grep "$cur" | grep -v '^#' | grep installed | sed -e 's/^\(\S\+\).*/\1/' ) )
;;
# complete addon names
*)
COMPREPLY=($(grep -h "^addon: $cur" /usr/share/vim/registry/*.yaml | sed -e 's/^addon:\s*//'))
;;
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