Created
July 27, 2011 20:34
-
-
Save mheiges/1110309 to your computer and use it in GitHub Desktop.
/etc/profile.d/apidb-tab-completion.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# bash tab completion functions and assignments for the ApiDB project | |
# | |
# $Id: apidb-tab-completion.sh 1314 2009-11-12 22:49:57Z mheiges $ | |
_instance_manager() { | |
COMPREPLY=() | |
local verbs="manage start stop restart status" | |
local man_tasks="start stop reload redeploy undeploy list deploy" | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
local action=${COMP_WORDS[1]} | |
local instance=${COMP_WORDS[2]} | |
local inst_list=$(find /usr/local/tomcat_instances -mindepth 1 \ | |
-maxdepth 1 -type d -regex '.+/[A-Z].+' | \ | |
xargs -n1 basename) | |
case "$prev" in | |
[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) | |
case "$action" in | |
manage) | |
COMPREPLY=( $(compgen -W "$man_tasks" -- "$cur") ) | |
;; | |
stop) | |
#COMPREPLY=( $(compgen -W "force" -- "$cur") ) | |
COMPREPLY='' | |
;; | |
*) | |
COMPREPLY='' | |
;; | |
esac | |
return 0 | |
;; | |
manage) | |
COMPREPLY=( $(compgen -W "$inst_list" -- "$cur") ) | |
return 0 | |
;; | |
start|stop|restart) | |
local opts | |
case "$action" in | |
manage) | |
opts="$(find /usr/local/tomcat_instances/$instance/conf/Catalina/localhost/ \ | |
-type f -not -name 'Instance_Template' | \ | |
xargs -i -n1 basename '{}' .xml)" | |
COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) | |
;; | |
*) | |
COMPREPLY=( $(compgen -W "$inst_list" -- "$cur") ) | |
;; | |
esac | |
return 0 | |
;; | |
redeploy|undeploy|reload) | |
webapps="$(find /usr/local/tomcat_instances/$instance/conf/Catalina/localhost/ -type f | xargs -i -n1 basename '{}' .xml)" | |
COMPREPLY=( $(compgen -W "$webapps" -- "$cur") ) | |
return 0 | |
;; | |
deploy) | |
;; | |
status|list) | |
COMPREPLY='' | |
;; | |
*) | |
COMPREPLY=($(compgen -W "$verbs" -- "$cur")) | |
;; | |
esac | |
return 0 | |
} | |
# use default for clean filename completion, filename completion | |
# with 'compgen -f' looks like ass | |
complete -F "_instance_manager" -o default "instance_manager" | |
############################################################################## | |
############################################################################## | |
_build() { | |
[ -z "$PROJECT_HOME" ] && return 0 | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
case "$prev" in | |
[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) | |
COMPREPLY=( $(compgen -W "install webinstall" -- "$cur") ) | |
;; | |
*) | |
case "$cur" in | |
*/*) | |
COMP_WORDBREAKS="$COMP_WORDBREAKS\/" | |
local dirs="$(find "$PROJECT_HOME/$cur"* -mindepth 0 -maxdepth 0 -type d | xargs -i -n1 basename '{}')" | |
dirs="$(for sub in $dirs; do echo "$(echo $sub | sed 's/\(.*\)\/.*/\1\//')"; done;)" | |
COMPREPLY=( $dirs ) | |
;; | |
-*) | |
COMPREPLY=( $(compgen -W "-append -webPropFile -installDBSchema -co" -- "$cur") ) | |
;; | |
*) | |
if [ ${#COMP_WORDS[@]} -eq 2 ]; then | |
local proj=$(find $PROJECT_HOME \ | |
-maxdepth 1 -mindepth 1 \ | |
-type d -not -name install | \ | |
xargs -n1 basename) | |
COMPREPLY=( $(compgen -W "$proj" -- "$cur") ) | |
fi | |
;; | |
esac | |
esac | |
} | |
#complete -F "_build" -o default "build" | |
############################################################################## | |
############################################################################## | |
_cattail() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
case "$prev" in | |
cattail|-*) | |
case "$cur" in | |
-*) | |
options="-a -t -c" | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
*) | |
local hosts="$(find /var/www -maxdepth 1 -type l | xargs -n1 -i basename '{}')" | |
COMPREPLY=( $(compgen -W "$hosts" -- "$cur") ) | |
;; | |
esac | |
;; | |
*\.*\.*) | |
local inst_list=$(find /usr/local/tomcat_instances -mindepth 1 \ | |
-maxdepth 1 -type d -regex '.+/[A-Z].+' | \ | |
xargs -n1 basename) | |
COMPREPLY=( $(compgen -W "$inst_list" -- "$cur") ) | |
;; | |
*) | |
;; | |
esac | |
} | |
complete -F "_cattail" "cattail" | |
complete -F "_cattail" "/usr/local/bin/cattail" | |
############################################################################## | |
############################################################################## | |
_ibuilder() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
case "$prev" in | |
ibuilder|-*) | |
case "$cur" in | |
*) | |
local hosts="$(find /var/www -maxdepth 1 -type l | xargs -n1 -i basename '{}')" | |
COMPREPLY=( $(compgen -W "$hosts" -- "$cur") ) | |
;; | |
esac | |
;; | |
*) | |
;; | |
esac | |
} | |
complete -F "_ibuilder" "ibuilder" | |
complete -F "_ibuilder" "/usr/local/bin/ibuilder" | |
############################################################################## | |
############################################################################## | |
_rebuilder() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
case "$prev" in | |
rebuilder|*) | |
case "$cur" in | |
-*) | |
options="--reinstall-config" | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
*) | |
local hosts="$(find /var/www -maxdepth 1 -type l | xargs -n1 -i basename '{}')" | |
COMPREPLY=( $(compgen -W "$hosts" -- "$cur") ) | |
;; | |
esac | |
;; | |
*) | |
;; | |
esac | |
} | |
complete -F "_rebuilder" "rebuilder" | |
complete -F "_rebuilder" "/usr/local/bin/rebuilder" | |
############################################################################## | |
############################################################################## | |
_wdkCache() { | |
[[ -z "$PROJECT_HOME" || -z "$GUS_HOME" ]] && return | |
# guess the model name from PROJECT_HOME path | |
local tmp="$(echo ${PROJECT_HOME#/var/www/})" | |
local model="$(echo ${tmp%%/*})" | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
local options="-drop -dropSingle -forceDrop -model -new -noSchemaOutput \ | |
-purge -recreate -reset -show" | |
case "$prev" in | |
wdkCache) | |
case "$cur" in | |
-*) | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
*) | |
if [[ "$PROJECT_HOME" == "$model" ]]; then | |
COMPREPLY="-model" | |
else | |
COMPREPLY="${cur}-model ${model}" | |
fi | |
;; | |
esac | |
;; | |
-model) | |
[[ "$PROJECT_HOME" == "$model" ]] && return | |
COMPREPLY=( $(compgen -W "$model" -- "$cur") ) | |
;; | |
*) | |
case "$cur" in | |
*) | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
esac | |
;; | |
esac | |
} | |
complete -F "_wdkCache" "wdkCache" | |
############################################################################## | |
############################################################################## | |
_wdkSanityTest() { | |
[[ -z "$PROJECT_HOME" || -z "$GUS_HOME" ]] && return | |
# guess the model name from PROJECT_HOME path | |
local tmp="$(echo ${PROJECT_HOME#/var/www/})" | |
local model="$(echo ${tmp%%/*})" | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local prev="${COMP_WORDS[COMP_CWORD-1]}" | |
local options="-model -failuresOnly -indexOnly -t -verbose" | |
case "$prev" in | |
wdkSanityTest) | |
case "$cur" in | |
-*) | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
*) | |
if [[ "$PROJECT_HOME" == "$model" ]]; then | |
COMPREPLY="-model" | |
else | |
COMPREPLY="${cur}-model ${model}" | |
fi | |
;; | |
esac | |
;; | |
-model) | |
[[ "$PROJECT_HOME" == "$model" ]] && return | |
COMPREPLY=( $(compgen -W "$model" -- "$cur") ) | |
;; | |
*) | |
case "$cur" in | |
*) | |
COMPREPLY=( $(compgen -W "$options" -- "$cur") ) | |
;; | |
esac | |
;; | |
esac | |
} | |
complete -F "_wdkSanityTest" "wdkSanityTest" | |
############################################################################## | |
############################################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment