The addhistory hook previously had two bugs when inc_append_history
or share_history was not set:
1. Commands were only saved to one history file (HISTFILE or per-dir)
depending on when fc -AI was called, resulting in lost history.
2. fc -p was called unconditionally after every command, corrupting
the zsh history stack even in global mode. This caused the per-dir
hook to push a new history frame on every command, breaking the
global history state.
Fix: always write both history files via fc -AI before any mode
check, and only call fc -p (to push into per-directory history)
when actually in directory mode.
The in memory history is not updated until an accept line command, so you
have to push enter before it is correct, this commit replaces the reset-prompt
with an accept-line. It also adds a push-line, to preserve the current editing
buffer
Use the HISTFILE environment variable in place of copying it to
_per_directory_history_global so that users can change the environment variable
after sourcing per-directory-history and have the global variable set correctly
This is a implementation of per directory history for zsh, some
implementations of which exist in bash[1,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.
[1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
[2]: http://dieter.plaetinck.be/per_directory_bash