It's not very efficient, but I don't feel it needs to be, and it requires no particular setup (except setting Bash to keep history forever but that's something useful I would do anyway for other use cases).
A line like
"\e[A": history-search-backward
only shows history entries that start with the current text when you hit cursor-up, for instance.[1] https://www.gnu.org/savannah-checkouts/gnu/bash/manual/html_...
Wrapping the winning command with a memorable function makes it a bit easier for me to recall the right incantation via fuzzy searching. For example: "set default" (resolves to dwim-shell-commands-macos-set-default-app) vs "duti" (which I can never remember).
It stores shell history in a SQLite database and you can use Ctrl+R to fuzzy search it.
As a matter of fact, I automatically (subconsciously) type control-r before every command.
I think I've only ever typed this command once:
git log --graph --decorate --oneline --allEssentially, you just mark the code blocks with `:script name`, and then can list or execute the block from a terminal. This also keeps the script in context within whatever other notes you had on the topic, when you were figuring it out etc. And if something turns out to be a useful snippet, you move it out to an actually separate script. :)
Typinator lets you use what's on the clipboard but also add scripting (say, Python or JavaScript) when certain parameters need to be calculated, like sizes or names.