Context
Typeahead in bash: good
When a bash shell is busy (initializing, running a command), one can type before the next prompt appears.
If the shell has launched a program, that program will capture the keys, but if no program is run or if the program does not capture input, what one types gets inserted in the shell after prompt appears.
For example : type sleep 5
, press Enter, then type ls
and press Enter. ls
will be run after sleep has finished. In real life, ls
would be replaced by cp
, rsync
or many other programs.
This is a typical Typeahead feature and it's a great time saver when you know in advance what to type.
It's also very nice since it allows to copy-paste several commands and have them run in sequence.
Real-world use case include when the shell takes time to initialize. It could be that the computer is slowed down for any reason, or the shell is on a slow network link, etc.
History search in bash: good
On a bash prompt, one can type Ctrl-R
to search through history.
This is an invaluable time saver when reusing some old command lines, or even sequence of command lines. Press Ctrl-R
, type a few characters typical of the command to search, press Ctrl-O
as many times as needed to replay the recorded commands from there.
Typeahead in history search: how ?
There is one limitation, though. Often I use the sequence above and find that if I type e.g. Ctrl-R ls
before the shell prompt has actually appeared, the Ctrl-R
part is ignored but the ls
part is shown.
The net effect is that one has to wait for the shell prompt to appear before typing Ctrl-R
, defeating part of the time saved.
Question
Is there a way to have Ctrl-R
honoured even in a typeahead situation ?
stty rprnt undef
in my .bashrc. According to my rcs log I added it in 16 years ago, and, sadly, I'd forgotten all about it...