Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash completion - how to get rid of unneeded tab presses?

I use

cur="${COMP_WORDS[COMP_CWORD]}" 

opts=`sqlite3 test.db "${QUERY[COMP_CWORD]}"`

SAVEIFS="$IFS"

IFS=$'\n'

COMPREPLY=( $(compgen -S"'" -P"'" -W "${opts}" $cur) )

IFS="$SAVEIFS"

to get possible variants from the database and complete them with TAB. As long as these variants could contain spaces, it is convinient to autoquote them using ' as prefix and suffix, so when I press A, B, TAB and there is only one variant with AB prefix, then I get something like 'ABC DEF'.

But the problem is that if there are many variants then after A, B, TAB I get 'AB, then I press TAB once again and it is NOP, and only at the third TAB press I get possible completions.

Is there a way to reduce TAB pressings to one or at least two?

like image 813
sknaumov Avatar asked Jan 18 '12 21:01

sknaumov


1 Answers

You can try:

bind 'set show-all-if-ambiguous on'

From man bash:

   show-all-if-ambiguous (Off)
          This alters the default behavior of the completion functions.  If set 
          to on, words which have more than one possible completion cause the 
          matches to be listed immediately instead of ringing the bell.
like image 188
Dennis Williamson Avatar answered Sep 29 '22 00:09

Dennis Williamson