Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created December 3, 2010 12:46
Show Gist options
  • Select an option

  • Save nojimage/726915 to your computer and use it in GitHub Desktop.

Select an option

Save nojimage/726915 to your computer and use it in GitHub Desktop.
cakephp bash completion
###
# @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
@nojimage
Copy link
Copy Markdown
Author

nojimage commented Dec 3, 2010

for CakePHP 1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment