When we need to search history in bash but multi command same pattern, you must type difference longest chain of result you want.

Example, my history bellow:

$ history
ssh srv-local-1
ssh srv-local-2
ssh srv-local-6
ping google.com
telnet srv-local-1
ssh srv-partner-1
ping srv-partner-6
ssh srv-partner-6

So, when I want retrieve command ssh srv-partner-6 I use control (^) + r (in macos) maybe I type (as short as possible): ping (because latest command used match pattern).

But when retrieve command ssh srv-local-1 you maybe type ssh with enter control + r multi time.

But when modify bind key control + r to history-incremental-pattern-search-backward you only need type intermittently different word by use regex.

echo "bindkey '^R' history-incremental-pattern-search-backward" >> ~/.zshrc
source ~/.zshrc

Now we can search ssh srv-local-1 by type:

~ ssh srv-local-1
bck-i-search: ssh*l*1_

Leave a Reply

Your email address will not be published. Required fields are marked *