]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/gradle/gradle.plugin.zsh
add xbindkeysrc
[dotfiles.git] / zsh / plugins / gradle / gradle.plugin.zsh
1 #!zsh
2 ##############################################################################
3 # A descriptive listing of core Gradle commands
4 ############################################################################
5 function _gradle_core_commands() {
6 local ret=1 state
7 _arguments ':subcommand:->subcommand' && ret=0
8
9 case $state in
10 subcommand)
11 subcommands=(
12 "properties:Display all project properties"
13 "tasks:Calculate and display all tasks"
14 "dependencies:Calculate and display all dependencies"
15 "projects:Discover and display all sub-projects"
16 "build:Build the project"
17 "help:Display help"
18 )
19 _describe -t subcommands 'gradle subcommands' subcommands && ret=0
20 esac
21
22 return ret
23 }
24
25 function _gradle_arguments() {
26 _arguments -C \
27 '-a[Do not rebuild project dependencies]' \
28 '-h[Help]' \
29 '-D[System property]' \
30 '-d[Log at the debug level]' \
31 '--gui[Launches the Gradle GUI app]' \
32 '--stop[Stop the Gradle daemon]' \
33 '--daemon[Use the Gradle daemon]' \
34 '--no-daemon[Do not use the Gradle daemon]' \
35 '--no-opt[Do not perform any task optimization]' \
36 '-i[Log at the info level]' \
37 '-m[Dry run]' \
38 '-P[Set a project property]' \
39 '--profile[Profile the build time]' \
40 '-q[Log at the quiet level (only show errors)]' \
41 '-v[Print the Gradle version info]' \
42 '-x[Specify a task to be excluded]' \
43 '*::command:->command' \
44 && return 0
45 }
46
47
48 ##############################################################################
49 # Are we in a directory containing a build.gradle file?
50 ############################################################################
51 function in_gradle() {
52 if [[ -f build.gradle ]]; then
53 echo 1
54 fi
55 }
56
57 ############################################################################
58 # Define the stat_cmd command based on platform behavior
59 ##########################################################################
60 stat -f%m . > /dev/null 2>&1
61 if [ "$?" = 0 ]; then
62 stat_cmd=(stat -f%m)
63 else
64 stat_cmd=(stat -L --format=%Y)
65 fi
66
67 ############################################################################## Examine the build.gradle file to see if its
68 # timestamp has changed, and if so, regen
69 # the .gradle_tasks cache file
70 ############################################################################
71 _gradle_does_task_list_need_generating () {
72 if [ ! -f .gradletasknamecache ]; then return 0;
73 else
74 accurate=$($stat_cmd .gradletasknamecache)
75 changed=$($stat_cmd build.gradle)
76 return $(expr $accurate '>=' $changed)
77 fi
78 }
79
80
81 ##############################################################################
82 # Discover the gradle tasks by running "gradle tasks --all"
83 ############################################################################
84 _gradle_tasks () {
85 if [ in_gradle ]; then
86 _gradle_arguments
87 if _gradle_does_task_list_need_generating; then
88 gradle tasks --all | grep "^[ ]*[a-zA-Z0-9]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
89 fi
90 compadd -X "==== Gradle Tasks ====" `cat .gradletasknamecache`
91 fi
92 }
93
94 _gradlew_tasks () {
95 if [ in_gradle ]; then
96 _gradle_arguments
97 if _gradle_does_task_list_need_generating; then
98 gradlew tasks --all | grep "^[ ]*[a-zA-Z0-9]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
99 fi
100 compadd -X "==== Gradlew Tasks ====" `cat .gradletasknamecache`
101 fi
102 }
103
104
105 ##############################################################################
106 # Register the completions against the gradle and gradlew commands
107 ############################################################################
108 compdef _gradle_tasks gradle
109 compdef _gradlew_tasks gradlew
110
111
112 ##############################################################################
113 # Open questions for future improvements:
114 # 1) Should 'gradle tasks' use --all or just the regular set?
115 # 2) Should gradlew use the same approach as gradle?
116 # 3) Should only the " - " be replaced with a colon so it can work
117 # with the richer descriptive method of _arguments?
118 # gradle tasks | grep "^[a-zA-Z0-9]*\ -\ " | sed "s/ - /\:/"
119 #############################################################################