zsh-users
 help / color / mirror / code / Atom feed
* how to prevent writing to HISTFILE with custom zshaddhistory?
@ 2017-03-24  0:58 Timothee Cour
  2017-03-30 21:17 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Timothee Cour @ 2017-03-24  0:58 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 460 bytes --]

neither SHARE_HISTORY, INC_APPEND_HISTORY, INC_APPEND_HISTORY_TIME is good
enough in my use case so i want to do the work in zshaddhistory:

unsetopt SHARE_HISTORY

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

how do I prevent the automatic writing to $HISTFILE?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: how to prevent writing to HISTFILE with custom zshaddhistory?
  2017-03-24  0:58 how to prevent writing to HISTFILE with custom zshaddhistory? Timothee Cour
@ 2017-03-30 21:17 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2017-03-30 21:17 UTC (permalink / raw)
  To: Zsh Users

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
reason.

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-30 21:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24  0:58 how to prevent writing to HISTFILE with custom zshaddhistory? Timothee Cour
2017-03-30 21:17 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).