Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Finer control over what gets written to the history file
On Tue, 15 Oct 2013 22:25:04 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Incidentally ...
>
> On Oct 15, 5:58pm, Peter Stephenson quoted the docs:
> >
> > zshaddhistory
> > The following example function first adds the history line to
> > the normal history with the newline stripped, which is usually
> > the correct behaviour. Then it switches the history context so
> > that the line will be written to a history file in the current
> > directory.
> >
> > zshaddhistory() {
> > print -sr -- ${1%%$'\n'}
> > fc -p .zsh_local_history
> > }
>
> This doesn't quite work, does it? The missing bit being that you also
> must have INC_APPEND_HISTORY set, otherwise the stack is popped before
> anything is written.
Yes, that needs adding.
diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo
index 78bdfc0..1f58df8 100644
--- a/Doc/Zsh/func.yo
+++ b/Doc/Zsh/func.yo
@@ -274,10 +274,13 @@ that in the global tt(HISTFILE) parameter. This is handled specially:
the history context is automatically restored after the processing
of the history line is finished.
-The following example function first adds the history line to the normal
-history with the newline stripped, which is usually the correct behaviour.
-Then it switches the history context so that the line will
-be written to a history file in the current directory.
+The following example function works with one of the options
+tt(INC_APPEND_HISTORY) or tt(SHARE_HISTORY) set, in order that the line
+is written out immediately after the history entry is added. It first
+adds the history line to the normal history with the newline stripped,
+which is usually the correct behaviour. Then it switches the history
+context so that the line will be written to a history file in the
+current directory.
example(zshaddhistory+LPAR()RPAR() {
print -sr -- ${1%%$'\n'}
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author