grails.plugin.zsh 1.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
_enumerateGrailsScripts() {
    # Default directoryies
    directories=($GRAILS_HOME/scripts ~/.grails/scripts ./scripts)

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