Sometimes when I reverse-search cmd in a shell I don't find a correct match and just want to execute search query as it is.
Is there a way in bash/zsh and friends to execute it without discarding input?
In zsh, you can use the variables LASTSEARCH and LASTABORTEDSEARCH. They're only available inside editor widgets.
An editor widget is a function that has been made into an editor widget with zle -N and that is invoked via a key binding. (The key binding can be ESC-x — : in vi mode.)
For example, the following code binds ESC-s to replace the current command line with the last incremental search. If you press ESC-s during an incremental search, that's the search in progress (which gets aborted).
function set-buffer-last-search { LBUFFER=$LASTSEARCH; RBUFFER=; }
zle -N set-buffer-last-search
bindkey '\es' set-buffer-last-search