[Bash-completion-devel] improving java completion

Mattias Ulbrich ulbrich at kit.edu
Thu Mar 24 17:43:44 UTC 2011


Hello everybody,

I am using java quite a lot and have noticed that the bash completion
for it does not always work perfectly. If, for instance, I have two
files
   path/a/b/C.class
   path/x/Y.class

and type
   java -cp path a.
I do not get any completion proposals. I would like to have "a.b." as a
proposed extension. This works only for the last level, such as in
   java -cp path a.b.
   java -cp path x.
where I get indeed the intended proposals.

I investigated completions/java and found out that the code

--- 8< ---
# Intentionally looking for *.class only in $i (not subdirs),
# see Debian bug #496828.
COMPREPLY=( "${COMPREPLY[@]}"
   $( command ls $i/$cur*.class 2>/dev/null | \
        sed -ne '/\$/d' -e "s|^$i//*||p" ) )
--- 8< ---

is responsible for the problem. I propose to replace this statement by

--- 8< ---
compopt -o nospace
COMPREPLY=( "${COMPREPLY[@]}"
            $( compgen -d -- $i/$cur | sed -e "s|^$i/\(.*\)|\1.|" )
            $( compgen -f -X '!*.class' -- $i/$cur | sed -e "s|^$i/||" )
         )
--- 8< ---

which works perfectly for me.

Thought, I could share that with the community and hope it helps.

Cheers,
   Mattias




More information about the Bash-completion-devel mailing list