2

Is it possible when I press Ctrl+r and after this, for example, press the letter a, then using the up and down arrow key to search only the commands in the history that start with a? Or if I type ssh and then use the arrow keys to search commands that start with ssh.

Is there a script that can implement this?

Sylvain Pineau
  • 61,564
  • 18
  • 149
  • 183
user1800997
  • 377
  • 1
  • 4
  • 17
  • What you are asking is not called [`bash completion`](http://www.tldp.org/LDP/abs/html/tabexpansion.html)... – anishsane Dec 13 '16 at 06:01

1 Answers1

3

You can even avoid the need of typing Ctrl+r by adding these two lines to your ~/.inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward

Up and down arrows will continue to browse your history if you press them at the bash prompt. But it will search for a command starting with the text to the left of the cursor if you type the beginning of a command like ssh.

Sylvain Pineau
  • 61,564
  • 18
  • 149
  • 183
  • Thanks, it's working. But with pressing ctrl+r it doesn't work, which is not a problem because only pressing a letter and then arrow key is faster. Just making a note. Is there a shortcut that can clear the active command? In Windows command prompt pressing ESC clear the typed commands and return the cursor in the beginning but in linux pressing ESC doesn't do that. – user1800997 Jul 07 '15 at 17:24
  • @user1800997 See my answer [here](http://askubuntu.com/a/470971/32239) – Sylvain Pineau Jul 07 '15 at 17:39