There is something confuse me when I implement a bash auto-completion function which I'll put it in /etc/bash_completion.d/
In order to achieve some feature, I want to remove the word break characters colon (:
) from variable $COMP_WORDBREAKS
and add a slash (/
) at begin of $COMP_WORDBREAKS
.
COMP_WORDBREAKS=" /'><=;|&("
_mytool()
{
local cur=${COMP_WORDS[COMP_CWORD]}
compopt -o nospace
# my implement here
COMPREPLY=( $(compgen ..........my_implement......... -- $cur) )
}
complete -F _mytool mytool
However, I can't reset COMP_WORDBREAKS
directly because the value is shared with other completion scripts. By the time the completion function gets called, variable COMP_WORDS
array has already been populated, so locally changes COMP_WORDBREAKS
have no effect.
Is there any solution for changing COMP_WORDBREAKS
in one completion script and no effect to other script?
$ echo $BASH_VERSION
4.2.10(1)-release
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…