zsh-users
 help / color / Atom feed
* Deleting entries in history
@ 2020-03-06 19:54 Manfred Lotz
  2020-03-06 21:15 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Manfred Lotz @ 2020-03-06 19:54 UTC (permalink / raw)
  To: Zsh-Users List

What is the proper way to delete entries in the history? 

Just load the history file in an editor, deleting things and save it? 

I didn't dare as I was afraid to interfere with the zsh shell managing
the history file.


-- 
Manfred

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

* Re: Deleting entries in history
  2020-03-06 19:54 Deleting entries in history Manfred Lotz
@ 2020-03-06 21:15 ` Bart Schaefer
  2020-03-06 21:17   ` Bart Schaefer
  2020-03-07 11:47   ` Manfred Lotz
  0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2020-03-06 21:15 UTC (permalink / raw)
  To: Manfred Lotz; +Cc: Zsh-Users List

On Fri, Mar 6, 2020 at 11:55 AM Manfred Lotz <ml_news@posteo.de> wrote:
>
> What is the proper way to delete entries in the history?
>
> Just load the history file in an editor, deleting things and save it?

The first thing to note is that when $SAVEHIST is nonzero, zsh will
typically update the file when the shell exits, so anything that is in
the runtime history of the current shell might reappear even after it
is deleted from the file.  I say "might" because this is affected by
the assorted setopts that control how the history is maintained.  The
only safe way to directly edit the history is to make sure no other
zsh is running that might rewrite it, and then set SAVEHIST=0 in your
current shell before doing anything else.

Once you are sure you have done that, then it should be OK to use an
editor on the history file.  Be aware that multi-line events (such as
"for" or "while" loops) are stored with lines terminated by backslash,
so if you start deleting a line that ends in backslash you need to
also delete all the adjacent lines that end in backslash, up to and
including the next following line that does NOT end in a backslash.
Single-line events never contain a backslash.

If you are using any of the setopts that store timestamped history
entries, each event will be prefixed by a ":" command that ends at the
next ";", with the timestamp between.  You should delete these along
with the event you want to remove, and avoid altering any that are on
other event lines.

All that said ... if the events you want to delete can all be matched
by some simple patterns, you might want to look into either a
zshaddhistory hook function, or a setting of the HISTORY_IGNORE
parameter.

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

* Re: Deleting entries in history
  2020-03-06 21:15 ` Bart Schaefer
@ 2020-03-06 21:17   ` Bart Schaefer
  2020-03-07 11:47   ` Manfred Lotz
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2020-03-06 21:17 UTC (permalink / raw)
  To: Manfred Lotz; +Cc: Zsh-Users List

On Fri, Mar 6, 2020 at 1:15 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Single-line events never contain a backslash.

Clarification:  Single-line events never contain a TRAILING backslash.
There may be backslashes quoting things like whitespace.  If you think
you see a trailing backslash, make sure it's not a quoted trailing
space or tab.

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

* Re: Deleting entries in history
  2020-03-06 21:15 ` Bart Schaefer
  2020-03-06 21:17   ` Bart Schaefer
@ 2020-03-07 11:47   ` Manfred Lotz
  1 sibling, 0 replies; 4+ messages in thread
From: Manfred Lotz @ 2020-03-07 11:47 UTC (permalink / raw)
  To: zsh-users

On Fri, 6 Mar 2020 13:15:10 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:

> On Fri, Mar 6, 2020 at 11:55 AM Manfred Lotz <ml_news@posteo.de>
> wrote:
> >
> > What is the proper way to delete entries in the history?
> >
> > Just load the history file in an editor, deleting things and save
> > it?  
> 
> The first thing to note is that when $SAVEHIST is nonzero, zsh will
> typically update the file when the shell exits, so anything that is in
> the runtime history of the current shell might reappear even after it
> is deleted from the file.  I say "might" because this is affected by
> the assorted setopts that control how the history is maintained.  The
> only safe way to directly edit the history is to make sure no other
> zsh is running that might rewrite it, and then set SAVEHIST=0 in your
> current shell before doing anything else.
> 

Ok, this means it is best done directly after reboot when I open the
first zsh shell.


> Once you are sure you have done that, then it should be OK to use an
> editor on the history file.  Be aware that multi-line events (such as
> "for" or "while" loops) are stored with lines terminated by backslash,
> so if you start deleting a line that ends in backslash you need to
> also delete all the adjacent lines that end in backslash, up to and
> including the next following line that does NOT end in a backslash.
> Single-line events never contain a backslash.
> 

OK, I can check this. 


> If you are using any of the setopts that store timestamped history
> entries, each event will be prefixed by a ":" command that ends at the
> next ";", with the timestamp between.  You should delete these along
> with the event you want to remove, and avoid altering any that are on
> other event lines.

Yep, I have those.

> 
> All that said ... if the events you want to delete can all be matched
> by some simple patterns, you might want to look into either a
> zshaddhistory hook function, or a setting of the HISTORY_IGNORE
> parameter.

I already use zshaddhistory for some commands I don't want to see in
the zsh history.


Thanks.

-- 
Manfred




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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 19:54 Deleting entries in history Manfred Lotz
2020-03-06 21:15 ` Bart Schaefer
2020-03-06 21:17   ` Bart Schaefer
2020-03-07 11:47   ` Manfred Lotz

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git