@@ -8,64 +8,65 @@ _comp_cmd_java__classpath()
8
8
}
9
9
10
10
# exact classpath determination
11
- _java_find_classpath ()
11
+ # @var[out] ret Array to store classpaths
12
+ # @return 0 if at least one element is generated, or otherwise 1
13
+ _comp_cmd_java__find_classpath ()
12
14
{
13
15
local i
14
16
15
- classpath =
17
+ ret =
16
18
17
19
# search first in current options
18
20
for (( i = 1 ; i < cword; i++ )) ; do
19
21
if [[ ${words[i]} == -@ (cp| classpath) ]]; then
20
- classpath =${words[i + 1]}
22
+ ret =${words[i + 1]}
21
23
break
22
24
fi
23
25
done
24
26
25
- # default to environment
26
- [[ ! $classpath ]] && classpath=${CLASSPATH-}
27
-
28
- # default to current directory
29
- [[ ! $classpath ]] && classpath=.
27
+ # fall back to environment, followed by current directory
28
+ _comp_split -F : ret " ${ret:- ${CLASSPATH:- .} } "
30
29
}
31
30
32
31
# exact sourcepath determination
33
- _java_find_sourcepath ()
32
+ # @var[out] ret Array to store sourcepaths
33
+ # @return 0 if at least one element is generated, or otherwise 1
34
+ _comp_cmd_java__find_sourcepath ()
34
35
{
35
36
local i
36
37
37
- sourcepath =
38
+ ret =
38
39
39
40
# search first in current options
40
41
for (( i = 1 ; i < cword; i++ )) ; do
41
42
if [[ ${words[i]} == -s ourcepath ]]; then
42
- sourcepath =${words[i + 1]}
43
+ ret =${words[i + 1]}
43
44
break
44
45
fi
45
46
done
46
47
47
- # default to classpath
48
- if [[ ! -v sourcepath ]]; then
49
- local classpath
50
- _java_find_classpath
51
- sourcepath=$classpath
48
+ # fall back to classpath
49
+ if [[ ! $ret ]]; then
50
+ _comp_cmd_java__find_classpath
51
+ return
52
52
fi
53
53
54
- _comp_split -F : sourcepath " $sourcepath "
54
+ _comp_split -F : ret " $ret "
55
55
}
56
56
57
57
# available classes completion
58
58
_comp_cmd_java__classes ()
59
59
{
60
- local classpath i
60
+ local ret i
61
61
62
62
# find which classpath to use
63
- _java_find_classpath
63
+ _comp_cmd_java__find_classpath
64
+ local -a classpaths=(" ${ret[@]} " )
64
65
65
66
# convert package syntax to path syntax
66
67
cur=${cur// .// }
67
68
# parse each classpath element for classes
68
- for i in ${classpath //:/ } ; do
69
+ for i in " ${classpaths[@]} " ; do
69
70
if [[ $i == * .@ (jar| zip) && -r $i ]]; then
70
71
if type zipinfo & > /dev/null; then
71
72
COMPREPLY+=($( zipinfo -1 " $i " " $cur *" 2> /dev/null |
@@ -105,16 +106,16 @@ _comp_cmd_java__classes()
105
106
# available packages completion
106
107
_comp_cmd_java__packages ()
107
108
{
108
- local sourcepath i files
109
+ local ret i files
109
110
110
111
# find which sourcepath to use
111
- _java_find_sourcepath
112
- (( ${ # sourcepath [@]})) || return 0
112
+ _comp_cmd_java__find_sourcepath || return 0
113
+ local -a sourcepaths=( " ${ret [@]}" )
113
114
114
115
# convert package syntax to path syntax
115
116
local cur=${cur// .// }
116
117
# parse each sourcepath element for packages
117
- for i in " ${sourcepath [@]} " ; do
118
+ for i in " ${sourcepaths [@]} " ; do
118
119
if [[ -d $i ]]; then
119
120
_comp_expand_glob files ' "$i/$cur"*'
120
121
(( ${# files[@]} )) || continue
0 commit comments