c6e8c856cb59e24362fe50fd93de097f30205420

Author
Zach Riggle <zach@riggle.me>
Committer
Zach Riggle <zach@riggle.me>
Date

Message

[plugins/grails] Added grails plugin

Diff

 1diff --git a/plugins/grails/grails.plugin.zsh b/plugins/grails/grails.plugin.zsh
 2new file mode 100755
 3index 0000000000000000000000000000000000000000..95b1324e7f522ad7dac824a590e2303c7c02eaba
 4--- /dev/null
 5+++ b/plugins/grails/grails.plugin.zsh
 6@@ -0,0 +1,62 @@
 7+
 8+if [[ ! -d $GRAILS_HOME/scripts ]];
 9+then
10+    echo "$0:"
11+    echo "Please set \$GRAILS_HOME to use the 'grails' plugin, and ensure that \$GRAILS_HOME/scripts exists"
12+fi
13+
14+_enumerateGrailsScripts() {
15+    # Default directoryies
16+    directories=($GRAILS_HOME/scripts ~/.grails/scripts ./scripts)
17+
18+    # Check all of the plugins directories, if they exist
19+    if [ -d plugins ]
20+    then
21+        directories+=(plugins/*/scripts)
22+    fi
23+    
24+    # Enumerate all of the Groovy files
25+    files=()
26+    for dir in $directories;
27+    do
28+        if [ -d $dir ]
29+        then
30+            files+=($dir/*.groovy)
31+        fi
32+    done
33+    
34+    # Don't try to basename ()
35+    if [ ${#files} -eq 0 ];
36+    then
37+        return
38+    fi
39+    
40+    # - Strip the path
41+    # - Remove all scripts with a leading '_'
42+    # - PackagePlugin_.groovy -> PackagePlugin
43+    # - PackagePlugin         -> Package-Plugin
44+    # - Package-Plugin        -> package-plugin
45+    basename $files                             \
46+        | grep -vE -e '^_'                      \
47+        | sed -E  -e 's/^_?([^_]+)_?.groovy/\1/'\
48+                  -e 's/([a-z])([A-Z])/\1-\2/g' \
49+        | tr "[:upper:]" "[:lower:]"            \
50+        | sort                                  \
51+        | uniq
52+}
53+ 
54+_grails() {
55+    if (( CURRENT == 2 )); then
56+        scripts=( $(_enumerateGrailsScripts) )
57+        
58+        if [ ${#scripts} -ne 0 ];
59+        then
60+            _multi_parts / scripts
61+            return
62+        fi
63+    fi
64+    
65+    _files
66+}
67+ 
68+compdef _grails grails