My dotfiles[1,2] are full of various functions to do stuff. Half of them I jacked from other people[3] when I was using Bash and ported to ZSH when I discovered Oh-my-zsh. However, a few are my own. The ones that I did write are often one-liners that take an argument and pass it to a series of commands that I'd rather not type. For example history | grep -i command, ls -lah | grep dir, or my favorite, cd dir; ls. If I have to do any logic, aside from determining what OS I'm on, I look to python.
You seem like the kind of person who'd appreciate Percol[1]. It's fantastic for shell history. I have it bound to Ctrl+R:
history | percol --prompt-bottom --result-bottom-up
I'm using fish, so the whole thing looks like this:
function _percol_key_bindings
function __percol_ctrl_r
set tempfile (mktemp)
history | percol --prompt-bottom --result-bottom-up >$tempfile
and commandline (cat $tempfile)
commandline -f repaint
rm -f $tempfile
end
# Bind Ctrl+R to percol history function for now
bind \cr '__percol_ctrl_r'
end