Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: how to prevent writing to HISTFILE with custom zshaddhistory?

On Mar 23,  5:58pm, Timothee Cour wrote:
} zshaddhistory(){
} local COMMAND_STR=${1%%$'\n'}
} print -r -- "$COMMAND_STR" >> $HISTFILE
} # from http://zsh.sourceforge.net/Doc/Release/Functions.html to avoid writing to $HISTFILE
} return 2
} }
} but this results in duplicate entries to $HISTFILE

I'm not able to reproduce duplication starting from "zsh -f", but it is
possible I'm just not running a large enough number of commands.

There are two possibly conflicting things going on here.

First, note that it's not actually safe to append text directly to
the history file like that.  History is no longer stored in a purely
plain-text format.  The example in the doc uses "print -s" for this

Second, in order to enforce the SAVEHIST limit, at shell exit (or at
other times depending on INC_APPEND_HISTORY etc.) the history file is
read in and then rewritten to keep only the trailing $SAVEHIST lines.
(It's reloaded to enforce HIST_SAVE_NO_DUPS etc.)  When the file is
reloaded the lines you appended will be put into the internal history,
but this time without the "don't save this" flag, which could result
in them being written out again later.

Depending on exactly what's happening, HIST_SAVE_NO_DUPS might be all
you need.

Or you could tell us why you think you need to append to the history
file this way, and maybe we can suggest a working approach.

Messages sorted by: Reverse Date, Date, Thread, Author