Better cake completion
Robby Russell authored on 10/10/2011 at 12:36:23... | ... |
@@ -1,18 +1,22 @@ |
1 | 1 |
# Set this to 1 if you want to cache the tasks |
2 |
-cache_task_list=1 |
|
2 |
+_cake_cache_task_list=1 |
|
3 | 3 |
|
4 | 4 |
# Cache filename |
5 |
-cache_file='.cake_task_cache' |
|
5 |
+_cake_task_cache_file='.cake_task_cache' |
|
6 |
+ |
|
7 |
+_cake_get_target_list () { |
|
8 |
+ cake | grep '^cake ' | sed -e "s/cake \([^ ]*\) .*/\1/" | grep -v '^$' |
|
9 |
+} |
|
6 | 10 |
|
7 | 11 |
_cake_does_target_list_need_generating () { |
8 | 12 |
|
9 |
- if [ $cache_task_list -eq 0 ]; then |
|
13 |
+ if [ ${_cake_cache_task_list} -eq 0 ]; then |
|
10 | 14 |
return 1; |
11 | 15 |
fi |
12 | 16 |
|
13 |
- if [ ! -f $cache_file ]; then return 0; |
|
17 |
+ if [ ! -f ${_cake_task_cache_file} ]; then return 0; |
|
14 | 18 |
else |
15 |
- accurate=$(stat -f%m $cache_file) |
|
19 |
+ accurate=$(stat -f%m $_cake_task_cache_file) |
|
16 | 20 |
changed=$(stat -f%m Cakefile) |
17 | 21 |
return $(expr $accurate '>=' $changed) |
18 | 22 |
fi |
... | ... |
@@ -21,12 +25,12 @@ _cake_does_target_list_need_generating () { |
21 | 21 |
_cake () { |
22 | 22 |
if [ -f Cakefile ]; then |
23 | 23 |
if _cake_does_target_list_need_generating; then |
24 |
- cake | sed -e "s/cake \([^ ]*\) .*/\1/" | grep -v '^$' > $cache_file |
|
25 |
- compadd `cat $cache_file` |
|
24 |
+ _cake_get_target_list > ${_cake_task_cache_file} |
|
25 |
+ compadd `cat ${_cake_task_cache_file}` |
|
26 | 26 |
else |
27 |
- compadd `cake | sed -e "s/cake \([^ ]*\) .*/\1/" | grep -v '^$'` |
|
27 |
+ compadd `_cake_get_target_list` |
|
28 | 28 |
fi |
29 | 29 |
fi |
30 | 30 |
} |
31 | 31 |
|
32 |
-compdef _cake cake |
|
32 |
+compdef _cake cake |
|
33 | 33 |
\ No newline at end of file |