diff options
author | Aaron Walker <ka0ttic@gentoo.org> | 2005-04-06 14:15:21 +0000 |
---|---|---|
committer | Aaron Walker <ka0ttic@gentoo.org> | 2005-04-06 14:15:21 +0000 |
commit | 5ae2d75d03f6d54c7c8cd1316b720365b8e91ad2 (patch) | |
tree | 1648d2b72c046e09dd1634950027fe0c4961295a /app-shells/bash-completion-config/files/bashcomp | |
parent | Version bump. (diff) | |
download | historical-5ae2d75d03f6d54c7c8cd1316b720365b8e91ad2.tar.gz historical-5ae2d75d03f6d54c7c8cd1316b720365b8e91ad2.tar.bz2 historical-5ae2d75d03f6d54c7c8cd1316b720365b8e91ad2.zip |
Revision bump; updated completion function to ignore *~. Keeping keywords.
Package-Manager: portage-2.0.51.19
Diffstat (limited to 'app-shells/bash-completion-config/files/bashcomp')
-rw-r--r-- | app-shells/bash-completion-config/files/bashcomp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/app-shells/bash-completion-config/files/bashcomp b/app-shells/bash-completion-config/files/bashcomp new file mode 100644 index 000000000000..64cf7df8abc3 --- /dev/null +++ b/app-shells/bash-completion-config/files/bashcomp @@ -0,0 +1,111 @@ +# Copyright 1999-2004 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: bashcomp,v 1.1 2005/04/06 14:15:21 ka0ttic Exp $ +# +# Author: Aaron Walker <ka0ttic%gentoo.org> +# +# completion for bash-completion-config + +# echo all completions in BASHCOMP_DIR +complete_avail() +{ + local bashcomp BASHCOMP_DIR="/usr/share/bash-completion" + for bashcomp in $BASHCOMP_DIR/* ; do + echo -n "${bashcomp##*/} " + done +} + +# echo all installed completions in $1 +complete_installed() +{ + local bashcomp + for bashcomp in $1/* ; do + echo -n "${bashcomp##*/} " + done +} + +# show completions for $1 +complete_on() +{ + local cur="$1" + + case "$2" in + install) + COMPREPLY=($(compgen -f -X '*~' -W "$(complete_avail)" -- "${cur}")) + ;; + uninstall) + if [ -z "$3" ] ; then + COMPREPLY=($(compgen -X '*~' -W "$(complete_installed \ + ${HOME}/.bash_completion.d)" -- "${cur}")) + else + COMPREPLY=($(compgen -X '*~' -W "$(complete_installed \ + /etc/bash_completion.d)" -- "${cur}")) + fi + ;; + esac +} + +_bash_completion_config() +{ + local cur prev opts i a=0 + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="-g --global -l --list -i --install -u --uninstall -h --help -d --debug -V --version -nc --nocolor" + + if [[ "${cur}" == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) + return 0 + fi + + case "${prev}" in + -nc|--nocolor|--nocolour) + COMPREPLY=($(compgen -W "${opts/-nc --nocolor/}" -- "${cur}")) + ;; + -d|--debug) + COMPREPLY=($(compgen -W "${opts/-d --debug/}" -- "${cur}")) + ;; + -g|--global) + for i in ${COMP_WORDS[@]} ; do + [[ "${i}" == "-i" || "${i}" == "--install" || + "${i}" == "-u" || "${i}" == "--uninstall" ]] && a=1 + [[ "${i}" == "-nc" || "${i}" == "--nocolor" || + "${i}" == "--nocolour" ]] && a=1 + done + + if [ ${a} -gt 0 ] ; then + action=install + complete_on "${cur}" "${action}" + else + COMPREPLY=($(compgen -W "-i --install -u --uninstall" -- "${cur}")) + fi + ;; + -i|--install) + action=install + complete_on "${cur}" "${action}" + ;; + -u|--uninstall) + action=uninstall + + for i in ${COMP_WORDS[@]} ; do + if [[ "${i}" == "-g" || "${i}" == "--global" ]] ; then + global=1 + fi + done + + if [ -z "${global}" ] ; then + complete_on "${cur}" "${action}" + else + complete_on "${cur}" "${action}" glob + fi + ;; + *) + [ -n "${action}" ] && complete_on "${cur}" "${action}" + ;; + esac + + unset global +} +complete -F _bash_completion_config bash-completion-config + +# vim: set ft=sh tw=80 sw=4 et : |