From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Finer control over what gets written to the history file
Date: Tue, 15 Oct 2013 17:58:38 +0100 [thread overview]
Message-ID: <20131015175838.19f0256d@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <131015094100.ZM2399@torch.brasslantern.com>
On Tue, 15 Oct 2013 09:41:00 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> I often find myself running a lot of similar but not quite identical
> commands to test some obscure bug or otherwise experiment with a shell
> construct. This stuff tends to push useful history out of the history
> file when I exit from the shell, if I don't remember to use my "die"
> alias that disables history and other exit-time operations.
>
> It'd be nice to be able to selectively exclude those from history after
> the fact, also without having to remember to type a leading space on
> every such line.
You know about the zshaddhistory hook? Excluding by pattern is a
fairly easy instance of this, and it should be readily extensible for
various different ways of checking. You could make it configurable by
styles.
zshistory_veto () {
local -a line
line=(${(Q)${(z)1}})
# too lazy to do the array stuff...
if [[ $line[1] = ${~HISTIGNORE} ]]
then
return 1
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook zshaddhistory zshaddhistory_veto
Just seen a typo.
zshaddhistory
Executed when a history line has been read interactively, but
before it is executed. The sole argument is the complete his‐
tory line (so that any terminating newline will still be
present).
If any of the hook functions return a non-zero value the history
line will not be saved, although it lingers in the history until
the next line is executed allow you to reuse or edit it immedi‐
ately.
A hook function may call `fc -p ...' to switch the history con‐
text so that the history is saved in a different file from the
that in the global HISTFILE parameter. This is handled spe‐
cially: 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.
zshaddhistory() {
print -sr -- ${1%%$'\n'}
fc -p .zsh_local_history
}
pws
next prev parent reply other threads:[~2013-10-15 16:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-15 16:41 Bart Schaefer
2013-10-15 16:58 ` Peter Stephenson [this message]
2013-10-16 0:34 ` Bart Schaefer
2013-10-16 8:55 ` Peter Stephenson
2013-10-16 9:20 ` Peter Stephenson
2013-10-17 14:20 ` Bart Schaefer
2013-10-17 14:28 ` Peter Stephenson
2013-10-16 10:04 ` Peter Stephenson
2013-10-16 5:25 ` Bart Schaefer
2013-10-16 8:35 ` Peter Stephenson
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=20131015175838.19f0256d@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@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).