当选项卡完成导出带有路径的环境变量时,变量名称丢失

当选项卡完成导出带有路径的环境变量时,变量名称丢失

我正在尝试使用制表符完成设置环境变量,例如

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

我曾经能够在输入export JAVA_HOME=部分后用 Tab 键完成文件夹,但是,当我尝试按 Tab 键时,我丢失了变量名称:

export JAVA_HOME=/u[tab]

变成:

export /usr/

我该如何解决?

我运行的是 Ubuntu 13.04。

编辑- 根据注释中的要求调试输出

$ 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

exclude='<>&'in__reassemble_comp_words_by_ref说关于=失踪COMP_WORDBREAKS

您可以使用 和 进行bash-4.*重现bash-completion-2.*

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

修复:添加=到您的COMP_WORDBREAKS.

相关内容