If you are using zsh and do a tab completion for commands, pathnames, options etc, whenever there are multiple potential matches the suggestions will be displayed below the prompt.
Once you chose a suggestion zsh will remove the list of suggestions out of the terminal, as you can see here:

enter image description here

Image source

In contrast when bash offers completion suggestions it outputs the list and returns you to a new prompt.

enter image description here

Image source
The zsh behaviour is preferable to me as the suggestions I never used offer no value and just produce more "noise" in the terminal.
Is it possible to configure bash/readline to behave like zsh in this way?


short: it's possible but complex as .inputrc bindings.

long: As suggested in a comment, you could do something like this in your bash prompt and readline bindings.

Saving/restoring the cursor would be ineffective, since the only point at which you would be able to reliably clear the remainder of the screen would be on pressing Enter to complete the selection.

Once you've passed control to accept-line, it is too late to clear the remainder of the screen. It's possible (but complex) to define a series of real and ad hoc "key bindings" to make readline to do more than one operation. See for example

But that approach limits you to sending characters to bash and issuing commands to readline. None of the readline commands does

printf '\033[J'

to clear the remainder of the screen. The closest would be readline's built-in clear-screen (not what you want). Your binding would have to do something like

  • beginning-of-line
  • insert "printf '\033[J';"
  • end-of-line
  • accept-line

The end-of-line would work around a quirk of readline. It allows you to press Enter anywhere on the line. If your cursor were in the middle of the line, you'd have just a fragment of your input left visible (although bash would get the entire string).

|improve this answer|||||
  • interesting. so with readline you cant really make a call out into a wider collection of functions. you are limited to the predefined actions. So the fundamentally the reason zsh can do this is because you can register a widget with the line editor. then bind a key to call the widget then the widget gives you all the scripting capabilities of a shell (not just the line editor) – the_velour_fog Aug 10 '16 at 1:06
  • right - bash's extensibility here is limited to what you can do to the command before submitting it. – Thomas Dickey Aug 10 '16 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.