Created
January 6, 2010 11:17
-
-
Save jetztgradnet/270209 to your computer and use it in GitHub Desktop.
Grails Bash completion (tested on OSX, Grails 1.2)
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
#export GRAILS_VERSION="$(ls -lhr $HOME/.grails | egrep -i '1\.' | head -1 | gawk '{print $9 }')" | |
export GRAILS_VERSION=`cat $GRAILS_HOME/build.properties | grep "^grails.version=" | awk -F= '{ print $2 }' | tr -d '\r' | tr -d '\n'` | |
_get_domain_classes(){ | |
find ./grails-app/domain -iname *.groovy 2> /dev/null | tr \\n ' ' | sed 's/\.groovy//g' | sed 's/\.\/grails-app\/domain\///g' | tr '/' \. | |
} | |
_get_tests(){ | |
find ./test -iname *.groovy 2> /dev/null | sed 's/\.\/test\/integration\///g' | sed 's/\Tests.groovy//g' | tr '/' \. | |
} | |
_get_plugins(){ | |
# plugin lists are placed at different locations for different Grails versions | |
find $HOME/.grails/$GRAILS_VERSION -name "plugins-list*.xml" -exec cat {} \; 2> /dev/null | grep \<plugin | awk -F"name=" '{print $2}' | sed 's/\"//g' | sed 's/\/\{0,1\}\>//g' | |
} | |
_get_scripts(){ | |
for D in $SCRIPT_DIRS; do | |
if [ -d $D ] | |
then ls -1 $D/*.groovy 2> /dev/null | sed -E 's/(.*)\/(.*)\.groovy/\2/' | sed -E 's/([A-Z])/-\1/g' | sed -E 's/^-//' | tr "[:upper:]" "[:lower:]" | |
fi | |
done | sort | uniq | grep -vE "^_" | |
} | |
_grails_comp(){ | |
local cur prev opts base | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
if [ -r ./grails-app ]; then | |
local projectName=`cat ./application.properties | grep "^app.name=" | awk -F= '{ print $2 }' | tr -d '\r' | tr -d '\n'` | |
SCRIPT_DIRS="$GRAILS_HOME/scripts ./scripts ~/.grails/scripts" | |
if [ -d plugins ] | |
then for PLUGIN_DIR in $(ls -d plugins/*/scripts 2> /dev/null); do | |
SCRIPT_DIRS="$SCRIPT_DIRS $PLUGIN_DIR" | |
done | |
fi | |
# get plugin scripts from project specific plugin directory under ~/.grails | |
if [ -d $HOME/.grails/$GRAILS_VERSION/projects/$projectName/plugins ] | |
then for PLUGIN_DIR in $(ls -d $HOME/.grails/$GRAILS_VERSION/projects/$projectName/plugins/*/scripts 2> /dev/null); do | |
SCRIPT_DIRS="$SCRIPT_DIRS $PLUGIN_DIR" | |
done | |
fi | |
opts=$(_get_scripts) | |
case "${prev}" in | |
generate-all) | |
local classes=$(_get_domain_classes) | |
COMPREPLY=( $(compgen -W "${classes}" -- ${cur}) ) | |
return 0 | |
;; | |
generate-views) | |
local classes=$(_get_domain_classes) | |
COMPREPLY=( $(compgen -W "${classes}" -- ${cur}) ) | |
return 0 | |
;; | |
generate-controller) | |
local classes=$(_get_domain_classes) | |
COMPREPLY=( $(compgen -W "${classes}" -- ${cur}) ) | |
return 0 | |
;; | |
test-app) | |
local test_classes=$(_get_tests) | |
COMPREPLY=( $(compgen -W "${test_classes}" -- ${cur}) ) | |
return 0 | |
;; | |
install-plugin) | |
local plugins=$(_get_plugins) | |
COMPREPLY=( $(compgen -W "${plugins}" -- ${cur}) ) | |
return 0 | |
;; | |
package-plugin) | |
COMPREPLY=( $(compgen -f) ) | |
return 0 | |
;; | |
plugin-info) | |
local plugins=$(opts) | |
COMPREPLY=( $(compgen -W "${plugins}" -- ${cur}) ) | |
return 0 | |
;; | |
help) | |
local opts=$(_get_scripts) | |
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | |
return 0 | |
;; | |
*) | |
;; | |
esac | |
if [[ "${opts}" =~ "${prev}" ]]; then | |
COMPREPLY=( $(compgen -f) ) | |
return 0 | |
fi | |
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | |
return 0 | |
else | |
opts="create-app create-plugin help list-plugins package-plugin plugin-info set-proxy" | |
case "${prev}" in | |
create-app) | |
COMPREPLY=( $(compgen -f) ) | |
return 0 | |
;; | |
create-plugin) | |
COMPREPLY=( $(compgen -f) ) | |
return 0 | |
;; | |
package-plugin) | |
COMPREPLY=( $(compgen -f) ) | |
return 0 | |
;; | |
plugin-info) | |
local plugins=$(_get_plugins) | |
COMPREPLY=( $(compgen -W "${plugins}" -- ${cur}) ) | |
return 0 | |
;; | |
*) | |
;; | |
esac | |
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | |
return 0 | |
fi | |
} | |
complete -F _grails_comp grails |
Hi Marco,
you can use it if you want, but as it is based on he original script by others (see my blog post at http://blog.jetztgrad.net/2010/01/updated-bash-completion-script-for-osx-and-grails-1-1-1-2/ for some pointers) you might ask them as well.
I haven't tested it against Grails 1.3.x, so you might need to give it a try. Also it's tested only with Mac OSX. If it does work on Ubuntu, fine, if not, you might want to use the original script (again see my blog post).
Regards,
Wolfgang
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'd like to know if I may use your script for inclusion in the Grails package for Ubuntu. The package is almost ready to go out, and then I came across your script. It might be very nice to add this to the package. Has it been maintained at all. Is it tested against 1.3.x?
Cheers,
Marco.