Bash完成 - 如何摆脱不必要的标签按?

skn*_*mov 9 bash shell bash-completion

我用

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"
Run Code Online (Sandbox Code Playgroud)

从数据库中获取可能的变体并完成它们TAB.只要这些变异可能包含空格,它是方便易使用,以autoquote它们'作为前缀和后缀,所以当我按下A,B,TAB和只有一个与变种AB前缀,然后我得到这样的事情'ABC DEF'.

但问题是,如果以后有很多变种,然后A,B,TAB我得到的'AB,然后我按TAB再次,它是NOP,只有在第三TAB按我得到尽可能完整.

有没有办法将TAB冲压减少到一个或至少两个?

Pau*_*ce. 12

你可以试试:

bind 'set show-all-if-ambiguous on'
Run Code Online (Sandbox Code Playgroud)

来自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.
Run Code Online (Sandbox Code Playgroud)

  • 如果不明显:将~set show-all-if-ambiguous on`添加到〜/ .inputrc以自动执行此操作. (4认同)