Skip to content

Commit e1b22b8

Browse files
committed
fix(java): fix _comp_cmd_java__packages for IFS/failglob/splitting
1 parent c1adce1 commit e1b22b8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

completions/java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ _comp_cmd_java__classes()
105105
# available packages completion
106106
_comp_cmd_java__packages()
107107
{
108-
local sourcepath i
108+
local sourcepath i files
109109

110110
# find which sourcepath to use
111111
_java_find_sourcepath
@@ -116,15 +116,17 @@ _comp_cmd_java__packages()
116116
# parse each sourcepath element for packages
117117
for i in "${sourcepath[@]}"; do
118118
if [[ -d $i ]]; then
119-
COMPREPLY+=($(command ls -F -d "$i/$cur"* 2>/dev/null |
120-
command sed -e 's|^'"$i"'/||'))
119+
_comp_expand_glob files '"$i/$cur"*'
120+
((${#files[@]})) || continue
121+
_comp_split -la COMPREPLY "$(
122+
command ls -F -d "${files[@]}" 2>/dev/null |
123+
command sed -e 's|^'"$i"'/||'
124+
)"
121125
fi
122126
done
123127
if ((${#COMPREPLY[@]} != 0)); then
124-
# keep only packages
125-
COMPREPLY=($(tr " " "\n" <<<"${COMPREPLY[@]}" | command grep "/$"))
126-
# remove packages extension
127-
COMPREPLY=(${COMPREPLY[@]%/})
128+
# keep only packages with the package suffix `/` being removed
129+
_comp_split -l COMPREPLY "$(printf '%s\n' "${COMPREPLY[@]}" | command sed -n 's,/$,,p')"
128130
# convert path syntax to package syntax
129131
cur="${COMPREPLY[*]//\//.}"
130132
fi

0 commit comments

Comments
 (0)