Last updated by
4 years ago
Page: Grails Bash Completion, Version:3
Author: Fernando Takai (http://fernandotakai.wordpress.com)This is a bash script that easily auto-completes all grails commands - for example, install-plugins lists all plugins, generate-(views|controller|all) completes domain classes, test-app all your tests and etc..This is the script:
To use it you have to have gawk (default on linux boxes -- but on mac, you have to install trough mac ports)To install it, you have to paste all this on a file and then add to your .bash_profile:[ -r /path/to/the/file ] && source /path/to/the/fileAnd login again! (su - your_user)To use it, just go your grails project and try:grails gener<tab><tab>grails generate-a<tab><tab>grails generate-all <tab><tab>
export GRAILS_VERSION="$(ls -lhr $HOME/.grails | egrep -i '1.' | head -1 | gawk '{print $9 }')"_filedir() { local IFS=$'tn' xspec #glob _expand || return 0 #glob=$(set +o|grep noglob) # save glob setting. #set -f # disable pathname expansion (globbing) if [ "${1:-}" = -d ]; then COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) ) #eval "$glob" # restore glob setting. return 0 fi xspec=${1:+"!*.$1"} # set only if glob passed in as $1 COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) $( compgen -d -- "$cur" ) ) #eval "$glob" # restore glob setting. }_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(){ cat $HOME/.grails/$GRAILS_VERSION/plugins/plugins-list.xml 2> /dev/null | grep <plugin | gawk -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 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 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 -f -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 -o filenames -o default -F _grails_comp grails