Bash Command Line Tab Fill Colon Character

I successfully completed bash for my user commands when the parameters did not contain special characters in them using the compression mechanism:

current=${COMP_WORDS[COMP_CWORD]} all=$(_get_all_items) COMPREPLY=( $(compgen -W "$all" -- $current) ) ... complete -F _prog_compl prog 

I use the same approach to populate elements that start with a colon :first :second , ... But it does not show me / auto-complete them. I tried to break out of the colon with a backslash, which didn't work either. How can I hide colons at the end?

Elements begin with a colon, let them say :first :second . If I write progname and start with a colon, like this:

 $ progname :<Tab here after colon> 

I see without completion , but two colons ("::") - one of them is automatically added to line I. If I convert the colon to a regular character (say, "b"), I get the completion exactly the way I want: bfirst , bsecond ...

It is important to note that when I click the tab, it places another ":" next to my previously inserted colon and becomes "::".

 $ bash --version GNU bash, version 4.1.10(2)-release (i486-slackware-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 

In addition, I have done several experiments in the shell that give:

 $ compgen -W ":aaaa5 :gb2 :cd3" -- ":" :aaaa5 :gb2 :cd3 

Nevertheless, it strangely puts another ":" on my only ":" and makes it "::" after entering: on the command line.

 $ complete complete -F _alp_compl alp.sh complete -o nospace -F __dbus_send dbus-send complete -F _myprog_compl myprog complete -o nospace -F __gdbus gdbus complete -o nospace -F __gsettings gsettings 
+5
source share
1 answer

After consulting with bash @ gnu.org, I got the answer:

The colon breaks the words for the termination system (see the description of the COMP_WORDBREAKS shell variable), so when you type

progname: [TAB]

the completion system receives an empty word for completion. If all possible terminations have `: 'as the longest common prefix, then the termination system inserts a colon into the string.

And my search for COMP_WORDBREAKS gives me an answer from fooobar.com/questions/425574 / ....

After fixing the (my missing) file / etc / bash _completion from the debian bash completion page , now my completion of the colon launch works like my will.

+4
source

Source: https://habr.com/ru/post/1200584/


All Articles