3

I'm trying to setup an environment variable using tab completion, e.g.

snowch$ export JAVA_HOME=/usr/lib/jvm/java-6-oracle/

I used to be able to tab complete the folders after typing the export JAVA_HOME= part however, when I try pressing tab I lose the variable name:

export JAVA_HOME=/u[tab]

turns to:

export /usr/

How do I fix this?

I am running Ubuntu 13.04.

EDIT - Debug output as requested in comments

$ bash --norc
bash-4.2$ . /etc/bash_completion
bash-4.2$ set -x
bash-4.2$ export JAVA_HOME=/u+ local compdir=./completions
+ [[ /usr/share/bash-completion/bash_completion == */* ]]
+ compdir=/usr/share/bash-completion/completions
+ . /usr/share/bash-completion/completions/export
+ return 124
+ local cur prev words cword
+ _init_completion -n =
+ local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -n =
+ case $flag in
+ exclude+==
+ getopts n:e:o:i:s flag -n =
+ COMPREPLY=()
+ local 'redir=@(?([0-9])<|?([0-9&])>?(>)|>&)'
+ _get_comp_words_by_ref -n '=<>&' cur prev words cword
+ local exclude flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur vcword vprev vwords
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ case $flag in
+ exclude='=<>&'
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ [[ 6 -ge 3 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ let 'OPTIND += 1'
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ let 'OPTIND += 1'
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ let 'OPTIND += 1'
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ let 'OPTIND += 1'
+ [[ 6 -ge 7 ]]
+ __get_cword_at_cursor_by_ref '=<>&' words cword cur
+ words=()
+ local cword words
+ __reassemble_comp_words_by_ref '=<>&' words cword
+ local exclude i j line ref
+ [[ -n =<>& ]]
+ exclude='<>&'
+ eval cword=1
++ cword=1
+ [[ -n <>& ]]
+ line='export JAVA_HOME=/u'
+ (( i=0, j=0 ))
+ (( i < 2 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ eval 'words[0]=${!ref}${COMP_WORDS[i]}'
++ words[0]=export
+ line=' JAVA_HOME=/u'
+ [[ 0 == 1 ]]
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 1 -gt 0 ]]
+ [[ JAVA_HOME=/u == +([<>&]) ]]
+ ref='words[1]'
+ eval 'words[1]=${!ref}${COMP_WORDS[i]}'
++ words[1]=JAVA_HOME=/u
+ line=
+ [[ 1 == 1 ]]
+ eval cword=1
++ cword=1
+ (( i++, j++ ))
+ (( i < 2 ))
+ local i cur index=19 'lead=export JAVA_HOME=/u'
+ [[ 19 -gt 0 ]]
+ [[ -n export JAVA_HOME=/u ]]
+ [[ -n exportJAVA_HOME=/u ]]
+ cur='export JAVA_HOME=/u'
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 19 -ge 6 ]]
+ [[ export != \e\x\p\o\r\t ]]
+ [[ 0 -lt 1 ]]
+ local old_size=19
+ cur=' JAVA_HOME=/u'
+ local new_size=13
+ index=13
+ (( ++i  ))
+ (( i <= cword ))
+ [[ 13 -ge 12 ]]
+ [[  JAVA_HOME=/ != \J\A\V\A\_\H\O\M\E\=\/\u ]]
+ cur=JAVA_HOME=/u
+ (( index-- ))
+ [[ 12 -ge 12 ]]
+ [[ JAVA_HOME=/u != \J\A\V\A\_\H\O\M\E\=\/\u ]]
+ [[ 1 -lt 1 ]]
+ (( ++i  ))
+ (( i <= cword ))
+ [[ -n JAVA_HOME=/u ]]
+ [[ ! -n JAVA_HOME=/u ]]
+ [[ 12 -lt 0 ]]
+ local words cword cur
+ _upvars -a2 words export JAVA_HOME=/u -v cword 1 -v cur JAVA_HOME=/u
+ ((  10  ))
+ ((  10  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  6  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  3  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=JAVA_HOME=/u
+ shift 3
+ ((  0  ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v $vcur "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v $vcword "$cword")
+ [[ -n prev ]]
+ [[ 1 -ge 1 ]]
+ upvars+=("$vprev")
+ upargs+=(-v $vprev "${words[cword - 1]}")
+ [[ -n words ]]
+ upvars+=("$vwords")
+ upargs+=(-a${#words[@]} $vwords "${words[@]}")
+ ((  4  ))
+ local cur cword prev words
+ _upvars -v cur JAVA_HOME=/u -v cword 1 -v prev export -a2 words export JAVA_HOME=/u
+ ((  13  ))
+ ((  13  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=JAVA_HOME=/u
+ shift 3
+ ((  10  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  7  ))
+ case $1 in
+ [[ -n prev ]]
+ unset -v prev
+ eval 'prev="$3"'
++ prev=export
+ shift 3
+ ((  4  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  0  ))
+ _variables
+ [[ JAVA_HOME=/u =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]
+ return 1
+ [[ JAVA_HOME=/u == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ [[ export == @(?([0-9])<|?([0-9&])>?(>)|>&) ]]
+ local i skip
+ (( i=1 ))
+ (( i < 2 ))
+ [[ JAVA_HOME=/u == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=2
+ (( 1 ))
+ (( i < 2 ))
+ [[ 1 -eq 0 ]]
+ prev=export
+ [[ -n '' ]]
+ return 0
+ local i action=variable remove=false
+ (( i=1 ))
+ (( i < cword ))
+ [[ JAVA_HOME=/u == *=\$* ]]
+ case $cur in
+ cur=/u
+ _filedir
+ local i 'IFS=
' xspec
+ _tilde /u
+ local result=0
+ [[ /u == \~* ]]
+ return 0
+ local -a toks
+ local quoted x tmp
+ _quote_readline_by_ref /u quoted
+ [[ /u == \'* ]]
+ printf -v quoted %q /u
+ [[ /u == \$* ]]
++ compgen -d -- /u
+ x=/usr
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ '' != -d ]]
+ xspec=
++ compgen -f -X '' -- /u
+ x=/usr
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ -n '' ]]
+ [[ 2 -ne 0 ]]
+ compopt -o filenames
+ COMPREPLY+=("${toks[@]}")
/usr/
  • 1
    Did you write any custom completion rules? When was the last time it worked? It still does here on Arch, so there's also a chance buntu is patching something badly. – lynxlynxlynx Jun 3 '13 at 12:56
  • @lynxlynxlynx - I don't have any custom completion rules. – Chris Snow Jun 3 '13 at 13:00
  • Repeat that after executing set -x. – Hauke Laging Jun 3 '13 at 14:29
  • @Hauke - I didn't write any custom completion rules. There may be some created by Ubuntu, but none have been created by me. – Chris Snow Jun 3 '13 at 14:45
  • Does this happen even if you start bash with bash --norc and then run . /etc/bash_completion? If not, post your .bashrc. – Gilles 'SO- stop being evil' Jun 3 '13 at 19:05
2

exclude='<>&' in __reassemble_comp_words_by_ref says about missing = in COMP_WORDBREAKS.

You can reproduce with bash-4.* and bash-completion-2.*:

COMP_WORDBREAKS=${COMP_WORDBREAKS//=}
export JAVA_HOME=/u<Tab>

Fix: add = to your COMP_WORDBREAKS.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.