So I guess this says a lot about me and the limited things I do on my Linux box as well as the power of ZSH’s searchable history, but I find myself rarely typing commands from scratch. Instead typing the first few letters of the command then using the up cursor arrow to search for the last time I ran that command. It is so, so useful. Rarely do I need to grep my way through my .history file. For commands such a checking a Duplicity backup to Backblaze’s B2 buckets, where I need long strings of my keys it is essential. But for even simple commands like updating my Gentoo setup it is just so useful.
Can you remember this every time?
Duplicity collection-status b2:// [22 character string]:[22 character string]@BucketName/folder
I should remember this one, but I never remember those parameters…
Emerge -uDNav @world —keep going
For bash that was:
history | grep xxxx
– Then typing the line number.
– Hitting ctrl-c to kill that command
– up cursor key then editing the command before hitting return.
With ZSH I type the first few characters and then the cursor. Even when you search and use the line number it allows you to edit that command before running it.
By default this behaviour is not enabled. But edit your .zshrc/.zprofile files and bind the UP/DOWN cursor keys to these two options:
bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward
Oh and if you use zsh (it’s the default shell on macOS nowadays) then you really should use Oh My Zsh