I am happily using zsh since a while now, and I am quite satisfied with my history settings, which are:# Write to history immediatelysetopt inc_append_history# History shared among terminalssetopt share_history# Save extended info in historysetopt extended_history# Ignore duplicatessetopt hist_ignoredupsBut 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.
Per-directory history in zsh
zsh;command history;oh my zsh
There is a plugin that claims to do exactly what you are looking for, appropriately named per directory history plugin: https://github.com/jimhester/oh-my-zsh/commit/baa187e4b903f39422a84b580e6e617ec3738e09Per-directory-history - tracks previous command history both per current directory and globally, with the ability to switch between them on the fly, bound to ctrl-g. says their wiki.I did not test it myself (yet), but according to the comments it should work.