After using this feature for a few days, I've noticed that saving search queries in history is bad. It pollutes history with meaningless lines.
New version. Added not-search condition on line 124 before "add current input to history".