Bind key to history-search
For searching lines starting with the typed, as you read in Macworld article, you can add the keybindings, for example:
- Up key bound to
history-search-backward
- Down key bound to
history-search-forward
To add them permanent edit your ~/.inputrc
like this
"\e[A": history-search-backward
"\e[B": history-search-forward
Same can be achieved using the bind
command in your ~/.bashrc
by pasting above lines within single-quotes ('
) as argument:
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
Note: for both settings to take effect you have to restart terminal !
Alternative: use built-in history search shortcuts
You can use Reverse History Search in Bash as explained in the question Searching your command history on macOS terminal.
Following shortcuts allow to search parts of commands in your Bash command history:
- Ctrl + r backwards
- Ctrl + s forwards
Tag typed commands for easy search later
Wouldn't above reverse-search be useful if you can set easy to remember keywords?
To leverage partial history search you can also append commands with comments, e.g. typing a command for later use:
ls -l *.sh # list scripts
The added comment (starting with #
) allows to search for list scripts
since the comment is recorded in history.