Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: how to prevent writing to HISTFILE with custom zshaddhistory?
- X-seq: zsh-users 22640
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: how to prevent writing to HISTFILE with custom zshaddhistory?
- Date: Thu, 30 Mar 2017 14:17:14 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=QWgtyQnLZZ/uYRD8hzVff/SbJSCYyR9ZISfk92hPbfc=; b=JrtCFwctRZ8NNucOSqbsVLpKdV4SkxeH6wVpUEmA6oEkixpuw/JtO7O6p0wpYuZBfH Pz31e9o2x3eeDu4jZcp9ryhi6BbQW1W1o4GYP/sDMQE73bRjoZPd6AdrfVPJWeaQYVT7 w6DbkDMpu/2Ug5zSsEpswg66Pi1AfBvP95WTy514sZr54RPl4Fo+EpZOu/H9ZTjYtRMJ pc+tle/qbJgfEqLZoniKBuSHIW6+p5MJOkJEfVJDtIczpAcWCSlo4RjXtupJyNDOo77t A9Jv/yZiW9l8N+QruCEG2huRdHFpYpnkw+DXhyHuuIkAxEr2XbBiOEZDS7MFRuhINiDJ 5uFA==
- In-reply-to: <CAM4j=kPAiOOfMRuoD+T9QpN9YBrwV_2w4E+zhbnenZDqQnGTHA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author