zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: how to prevent writing to HISTFILE with custom zshaddhistory?
Date: Thu, 30 Mar 2017 14:17:14 -0700	[thread overview]
Message-ID: <170330141714.ZM17092@torch.brasslantern.com> (raw)
In-Reply-To: <CAM4j=kPAiOOfMRuoD+T9QpN9YBrwV_2w4E+zhbnenZDqQnGTHA@mail.gmail.com>

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.


      reply	other threads:[~2017-03-30 21:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24  0:58 Timothee Cour
2017-03-30 21:17 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=170330141714.ZM17092@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).