How do I make bash completion behave like this?

0

I’m not sure if what I’m asking is possible, but what I would like bash to do on tab presses is this:

  • On the first tab press, expand a common prefix (skip/beep and do nothing, I don’t really mind, if there isn’t one)
  • On the second tab press, list out options
  • Any subsequent tab presses cycle through these options

If any key other than tab is pressed throughout the process, then the next tab press will behave as step one.

I managed to get one and two with this:

bind “set show-all-if-unmodified on”
bind ‘set menu-complete-display-prefix on’

And I managed to get one and three with this:

bind ‘set menu-complete-display-prefix on’
bind ‘TAB:menu-complete’

Combining all three options results in one and three, however.

How can I get the desired behaviour?

Thanks!

Aramis Razzaghipour

Posted 2019-02-11T19:59:40.727

Reputation: 3

Have you considered using zsh? I've heard it does this natively and by default, but bash can probably do it too. – QuickishFM – 2019-02-12T09:39:43.130

Answers

0

Setting these options in .inputrc is close:

set show-all-if-ambiguous on
set menu-complete-display-prefix on
TAB: menu-complete
set colored-completion-prefix on
set colored-stats on

It combines step one and two in a way that when you first press TAB it completes the common prefix and also shows the list of possible completions. Subsequent TAB presses cycle through them. I've found the "colored" options helpful so I've listed them as a bonus.

Zbyněk Winkler

Posted 2019-02-11T19:59:40.727

Reputation: 376