-
-
Save nojimage/726915 to your computer and use it in GitHub Desktop.
cakephp bash completion
This file contains hidden or 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
### | |
# @file CakePHP cake console bash completion script | |
# @author nojimage | |
# @original tclineks http://bin.cakephp.org/saved/21917 | |
# @license mit | |
_cake() | |
{ | |
local cur prev opts base | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
# for toplevel, find shells | |
if [[ ${COMP_CWORD} -eq 1 ]]; then | |
shells=`$1 | grep "Available Shells:" -A 50 | awk -F"\]|[\t ]*" '/^ .*? \[/ {for(i=1;i<=NF;i++){ if (!index($i, "\[") && length($i)) print $i}}'` | |
COMPREPLY=( $(compgen -W "${shells}" -- ${cur}) ) | |
return 0 | |
# list available options for bake, just help for others (for now) | |
elif [[ ${COMP_CWORD} -eq 2 ]]; then | |
case "${prev}" in | |
bake) | |
opts=`$1 bake help | awk '/^\tbake/ {print $2}'` | |
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | |
return 0 | |
;; | |
*) | |
COMPREPLY=( $(compgen -W "help" -- ${cur}) ) | |
return 0 | |
;; | |
esac | |
# when we're level three (or more) | |
else | |
prevprev="${COMP_WORDS[COMP_CWORD-2]}" | |
case "${prevprev}" in | |
bake) | |
case "${prev}" in | |
model | controller | view) | |
models=`$1 bake ${prev} <&- | awk '/^[0-9]+\./ {print $2}'` | |
COMPREPLY=( $(compgen -W "${models}" -- ${cur}) ) | |
return 0 | |
;; | |
*) | |
;; | |
esac | |
;; | |
*) | |
;; | |
esac | |
fi | |
} | |
complete -F _cake cake | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for CakePHP 1.3