@@ -8,62 +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
+
54
+ _comp_split -F : ret " $ret "
53
55
}
54
56
55
57
# available classes completion
56
58
_comp_cmd_java__classes ()
57
59
{
58
- local classpath i
60
+ local ret i
59
61
60
62
# find which classpath to use
61
- _java_find_classpath
63
+ _comp_cmd_java__find_classpath
64
+ local -a classpaths=(" ${ret[@]} " )
62
65
63
66
# convert package syntax to path syntax
64
67
cur=${cur// .// }
65
68
# parse each classpath element for classes
66
- for i in ${classpath //:/ } ; do
69
+ for i in " ${classpaths[@]} " ; do
67
70
if [[ $i == * .@ (jar| zip) && -r $i ]]; then
68
71
if type zipinfo & > /dev/null; then
69
72
COMPREPLY+=($( zipinfo -1 " $i " " $cur *" 2> /dev/null |
@@ -103,27 +106,30 @@ _comp_cmd_java__classes()
103
106
# available packages completion
104
107
_comp_cmd_java__packages ()
105
108
{
106
- local sourcepath i
109
+ local ret i files
107
110
108
111
# find which sourcepath to use
109
- _java_find_sourcepath
112
+ _comp_cmd_java__find_sourcepath || return 0
113
+ local -a sourcepaths=(" ${ret[@]} " )
110
114
111
115
# convert package syntax to path syntax
112
- cur=${cur// .// }
116
+ local cur=${cur// .// }
113
117
# parse each sourcepath element for packages
114
- for i in ${sourcepath //:/ } ; do
118
+ for i in " ${sourcepaths[@]} " ; do
115
119
if [[ -d $i ]]; then
116
- COMPREPLY+=($( command ls -F -d " $i /$cur " * 2> /dev/null |
117
- command sed -e ' s|^' " $i " ' /||' ) )
120
+ _comp_expand_glob files ' "$i/$cur"*'
121
+ (( ${# files[@]} )) || continue
122
+ _comp_split -la COMPREPLY " $(
123
+ command ls -F -d " ${files[@]} " 2> /dev/null |
124
+ command sed -e ' s|^' " $i " ' /||'
125
+ ) "
118
126
fi
119
127
done
120
128
if (( ${# COMPREPLY[@]} != 0 )) ; then
121
- # keep only packages
122
- COMPREPLY=($( tr " " " \n" <<< " ${COMPREPLY[@]}" | command grep " /$" ) )
123
- # remove packages extension
124
- COMPREPLY=(${COMPREPLY[@]%/ } )
129
+ # keep only packages with the package suffix `/` being removed
130
+ _comp_split -l COMPREPLY " $( printf ' %s\n' " ${COMPREPLY[@]} " | command sed -n ' s,/$,,p' ) "
125
131
# convert path syntax to package syntax
126
- cur= " ${COMPREPLY[* ]// \/ / .} "
132
+ (( ${ # COMPREPLY[@]} )) && COMPREPLY=( " ${COMPREPLY[@ ]// \/ / .} " )
127
133
fi
128
134
}
129
135
0 commit comments