Browse code

Merge pull request #595 from zachriggle/grails-plugin

Grails plugin

Robby Russell authored on 10/10/2011 at 12:42:56
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,54 @@
0
+_enumerateGrailsScripts() {
1
+    # Default directoryies
2
+    directories=($GRAILS_HOME/scripts ~/.grails/scripts ./scripts)
3
+
4
+    # Check all of the plugins directories, if they exist
5
+    if [ -d plugins ]
6
+    then
7
+        directories+=(plugins/*/scripts)
8
+    fi
9
+    
10
+    # Enumerate all of the Groovy files
11
+    files=()
12
+    for dir in $directories;
13
+    do
14
+        if [ -d $dir ]
15
+        then
16
+            files+=($dir/[^_]*.groovy)
17
+        fi
18
+    done
19
+    
20
+    # Don't try to basename ()
21
+    if [ ${#files} -eq 0 ];
22
+    then
23
+        return
24
+    fi
25
+    
26
+    # - Strip the path
27
+    # - Remove all scripts with a leading '_'
28
+    # - PackagePlugin_.groovy -> PackagePlugin
29
+    # - PackagePlugin         -> Package-Plugin
30
+    # - Package-Plugin        -> package-plugin
31
+    basename $files                             \
32
+        | sed -E  -e 's/^_?([^_]+)_?.groovy/\1/'\
33
+                  -e 's/([a-z])([A-Z])/\1-\2/g' \
34
+        | tr "[:upper:]" "[:lower:]"            \
35
+        | sort                                  \
36
+        | uniq
37
+}
38
+ 
39
+_grails() {
40
+    if (( CURRENT == 2 )); then
41
+        scripts=( $(_enumerateGrailsScripts) )
42
+        
43
+        if [ ${#scripts} -ne 0 ];
44
+        then
45
+            _multi_parts / scripts
46
+            return
47
+        fi
48
+    fi
49
+    
50
+    _files
51
+}
52
+ 
53
+compdef _grails grails