I actually made a CLI tool (https://github.com/ddworken/hishtory) that automatically binds to Control+R to support both history searching and AI queries (by prefixing queries with `?`).
Here's the prompt engineering I did: https://github.com/ddworken/hishtory/blob/master/shared/ai/a...