I am happily using zsh
since a while now, and I am quite satisfied with my history settings, which are:
# Write to history immediately
setopt inc_append_history
# History shared among terminals
setopt share_history
# Save extended info in history
setopt extended_history
# Ignore duplicates
setopt hist_ignoredups
But it happens often that I need to use specific commands inside some specific directories. For example, when I am in ~/my_project
I usually invoke make target1 && ./run1
, but when I am in ~/second_project
I usually need make target2 && cat foobar | ./run2
.
That is: different directories, but similar commands.
So, I usually cd ~/my_project
and type make
and then search backward in the history until I find what I need. But if it happen that I worked in second_project
, when searching the history I will find some commands that I do not need.
So, my question: does a plugin/setting/something exist for zsh such that, when searching in history, commands invoked in the current directory are displayed first?
Ideally, every other matching history command will appear after those, optionally specifying a max number of priority elements.
I would try to write something like this by myself, but I still do not know how to write custom zsh plugins, how to handle history and so on.