by phforms · 2mo ago · 0 comments
Usually what I do is writing these tricks down to a document that is easily accessible at a place where I know that I will look for when failing to remember them. I have a directory of docs where I write stuff like this down by language/tool/etc., so I can quickly look it up without having to search the internet. But I also have to actively remind myself that these things exist whenever I have a problem, stop me from just doing the inefficient thing.
So if you want to use ctrl-r, but you’re using the up key, use the down key to navigate back to a clear line, then use ctrl-r. Do it enough times and your brain will work overtime to find a shortcut (aka just doing it the new way).
"Use Ctrl-R for fuzzy history, or Ctrl-P/Ctrl-N for history entries"
(I have those bound to bindkey '^P' up-history and bindkey '^N' down-history instead of up and down arrow's "up-line-or-history" which is really annoying with multiline commands)
It's not even that bad of a habit with zsh either where it will only scroll through history matching a substring in your history, for instance if I type "rg -i" and then start pressing up arrow, it will only cycle through history entries starting with "rg -i".
though one function that i recently added will narrow your history down based on a space separated set of filters which i found useful
function hgrep
set -l cmd history
for pattern in $argv
set cmd "$cmd | grep -- "(string escape "$pattern")
end
eval $cmd | cat
end
use `hgrep ruby debug foo` would filter for a line that contained all the words ruby, debug and foo.bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
type eg "rg" then up or down arrow, and the history shown is filtered by that rg prefix.
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward
So far it works. Thank you diath. $ ,:(){ :|:& };: #forkbomb
This way, when I want to find it again, I CTRL-R and type ‘forkbomb’ .. voila, instant recall!All I have to remember is the small ontology I keep in my head for the most important commands I use .. pretty easy if I also construct a narrative for those commands, contextually. “#downup #clearlog #checkconn #amialone #forkbomb”, etc.
Seems like overkill until it saves my ass. It continues to do so almost half a decade into all the LLM hype. It hits the sweet spot between simplicity, convenience, reliability, and precision.
People strongly underestimate how good the git life can be, especially with all the blogspam on here trying to dethrone it lately.
Don't let IT hear that unless you work on FOSS.
I think for a digital solution to come close you need it permanently present on a nth monitor
what a time to be alive.
People had this same problem last century. They would use templates that fit over their keyboards with all the common shortcuts and commands printed on them. Sometimes they were for a specific program, but you could buy blank ones to write your own notes.
Today, "keyboard templates" have an entirely different meaning, so the best thing for this is paper. Print your shortcuts out on a piece of paper and put it near your monitor. You could even categorize them by writing them on different-colored Post-Its.
yes, it's improved a lot in the last couple of years! what in particular bothered you?
Was originally turned on to this by Derek Sivers: https://sive.rs/srs
"\e[A": history-search-backward
"\e[B": history-search-forward
in my .inputrc for years. I think, this is how command line worked in tcsh.It changes unconditional prev/next to prefix search. With empty command line it is the same as the old behavior. But if you enter "ls" and then press up-arrow, it will scroll through all commands in history that have "ls" as a prefix. I use it much more often than C-r.