Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created May 7, 2010 16:49
Show Gist options
  • Save dgmike/393697 to your computer and use it in GitHub Desktop.
Save dgmike/393697 to your computer and use it in GitHub Desktop.
Bash Completion for php PEAR
#
# bash completion support for PEAR installer.
#
# Author: Amir Mohammad Saied <amir@php.net>
# Based on: http://svn.php.net/viewvc/pear2/sandbox/PEAR_BashCompletion/trunk/pear?view=markup
#
# Puts this file in /usr/share/bash_completion/
#
# Create a symbolic link on /etc/bash_completion.d/
#
_pear()
{
local cur prev commands
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands=$(for c in `pear 2>&1 | awk '{ORS=" "} /[a-zA-Z-]+ / {print $1}'`; do echo ${c} ; done )
case "${prev}" in
build)
_filedir '@(xml)'
return 0
;;
bundle)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-d -f --destination --force" -- ${cur}) )
fi
return 0
;;
channel-alias|channel-delete|channel-info|channel-update)
_pear_discovered_channels
return 0
;;
convert)
_filedir '@(xml)'
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-f --flat" -- ${cur}) )
fi
return 0
;;
cvsdiff)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-q -Q -D -R -r -c -u -i -b -B -n \
--quiet --reallyquiet --date --release --revision \
--context --unified --ignore-case --ignore-whitespace \
--ignore-blank-lines --brief --dry-run" -- ${cur}) )
fi
_filedir
return 0
;;
cvstag)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-q -Q -F -d -n --quiet \
--reallyquiet --slide --delete--dry-run" -- ${cur}) )
fi
_filedir '@(xml)'
return 0
;;
download)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-Z --nocompress" -- ${cur}) )
fi
return 0
;;
download-all|remote-list)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-c --channel" -- ${cur}) )
fi
return 0
;;
install)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-f -l -n -r -s -B -Z -R -P -a -o \
-O -p --force --loose --nodeps --register-only --soft \
--nobuild --nocompress --installroot --ignore-errors \
--alldeps --onlyreqdeps --offline --pretend" -- ${cur}) )
fi
return 0
;;
list|search)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-c -a -i --channel --allchannels --channelinfo" -- ${cur}) )
else
_pear_installed_packages
fi
return 0
;;
list-all)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-c -i --channel --channelinfo" -- ${cur}) )
fi
return 0
;;
list-files)
_pear_installed_packages
return 0
;;
list-upgrades)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-i --channelinfo" -- ${cur}) )
fi
return 0
;;
login)
_pear_discovered_channels
return 0
;;
makerpm)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-t -p --spec-template --rpm-pkgname" -- ${cur}) )
fi
_filedir '@(tgz)'
return 0
;;
package|pickle)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-Z -n --nocompress --showname" -- ${cur}) )
fi
_filedir '@(xml)'
return 0
;;
package-dependencies|package-validate)
_filedir '@(xml)'
return 0
;;
run-tests)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-r -i -l -q -s -p -u -t -c -x \
--recur --ini --realtimelog --quiet --simple --package \
--phpunit --tapoutput --cgi --coverage" -- ${cur}) )
fi
return 0
;;
sign)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-v --verbose" -- ${cur}) )
fi
_filedir '@(tar|tgz)'
return 0
;;
uninstall|upgrade|run-scripts)
_pear_installed_packages
return 0
;;
upgrade-all)
if [[ "${cur}" == -* ]] ; then
COMPREPLY=( $(compgen -W "-n -r -B -Z -R --nodeps \
--register-only --nobuild --nocompress --installroot \
--ignore-errors --loose" -- ${cur}) )
fi
return 0
;;
*)
;;
esac
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
}
_pear_installed_packages()
{
local packages=$(for p in `pear list | tail -n"+4" | cut -d' ' -f1`; do echo ${p} ; done )
COMPREPLY=( $(compgen -W "${packages}" -- ${cur}) )
}
_pear_discovered_channels()
{
local channels=$(for c in `pear list-channels | tail -n"+4" | grep -v __uri | cut -d' ' -f1`; do echo ${c} ; done )
COMPREPLY=( $(compgen -W "${channels}" -- ${cur}) )
}
complete -F _pear pear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment