Per directory history for zsh, as well as global history, and the ability to toggle between them with ^G.
Shell
368
40 commits
updated Aug 27, 2026
Per directory history for zsh, as well as global history, and the ability to toggle between them with ^G.
This is a implementation of per directory history for zsh, some implementations of which exist in bash1,2. It also implements a per-directory-history-toggle-history function to change from using the directory history to using the global history. In both cases the history is always saved to both the global history and the directory history, so the toggle state will not effect the saved histories. Being able to switch between global and directory histories on the fly is a novel feature as far as I am aware.
This is a standalone repository for the script, however it is also included in oh-my-zsh as a plugin.
Load this script into your interactive ZSH session:
% source zsh-per-directory-history.zsh
The default mode if per directory history, interact with your history as normal.
Press ^G (the Control and G keys simultaneously) to toggle between local and global histories. If you would prefer a different shortcut to toggle set the PER_DIRECTORY_HISTORY_TOGGLE environment variable.
The integration suite requires only zsh and runs each scenario with isolated history files and a real interactive shell:
zsh tests/run.zsh
Tests marked XFAIL document reproduced correctness bugs. They do not fail CI,
but an unexpected pass does, so a bug fix must promote the corresponding test
to a normal passing test.
The idea/inspiration for a per directory history is from Stewart MacArthur and Dieter, the implementation idea is from Bart Schaefer. The implementation is by Jim Hester in September 2012.
487 followers · starred Sep 2019
45 followers · starred Jun 2020
67 followers · starred Feb 2013
52 followers · starred Apr 2025
Shell
100.0%
Per directory history for zsh, as well as global history, and the ability to toggle between them with ^G.
Shell
368
40 commits
updated Aug 27, 2026
Per directory history for zsh, as well as global history, and the ability to toggle between them with ^G.
This is a implementation of per directory history for zsh, some implementations of which exist in bash1,2. It also implements a per-directory-history-toggle-history function to change from using the directory history to using the global history. In both cases the history is always saved to both the global history and the directory history, so the toggle state will not effect the saved histories. Being able to switch between global and directory histories on the fly is a novel feature as far as I am aware.
This is a standalone repository for the script, however it is also included in oh-my-zsh as a plugin.
Load this script into your interactive ZSH session:
% source zsh-per-directory-history.zsh
The default mode if per directory history, interact with your history as normal.
Press ^G (the Control and G keys simultaneously) to toggle between local and global histories. If you would prefer a different shortcut to toggle set the PER_DIRECTORY_HISTORY_TOGGLE environment variable.
The integration suite requires only zsh and runs each scenario with isolated history files and a real interactive shell:
zsh tests/run.zsh
Tests marked XFAIL document reproduced correctness bugs. They do not fail CI,
but an unexpected pass does, so a bug fix must promote the corresponding test
to a normal passing test.
The idea/inspiration for a per directory history is from Stewart MacArthur and Dieter, the implementation idea is from Bart Schaefer. The implementation is by Jim Hester in September 2012.
487 followers · starred Sep 2019
45 followers · starred Jun 2020
67 followers · starred Feb 2013
52 followers · starred Apr 2025
Shell
100.0%