zsh-workers
 help / color / mirror / code / Atom feed
From: "Markus Näher" <markus.naeher@gmx.net>
To: zsh-workers@zsh.org
Subject: Re: Feature Request: fc -C to clear history and reset counter
Date: Wed, 20 May 2020 02:13:48 +0200	[thread overview]
Message-ID: <13178bd5-7b89-19a2-240f-f1886d2ffd2a@gmx.net> (raw)
In-Reply-To: <CAH+w=7ZDmfTpWH_Z1NQ=iCR9FxF=FTUF5Sigr7NAD_PtiJ4OkQ@mail.gmail.com>

On 20.05.20 00:58, Bart Schaefer wrote:
> On Tue, May 19, 2020 at 1:22 PM Markus Näher <markus.naeher@gmx.net> wrote:
>>
>> I have a second use case for clearing the history. I only started my
>> request with the use case that's easier to explain.
>>
>> For bash, I wrote a function that allows me to edit the _whole_ history
>> (not only the last entry like fc), even reorder entries.
>>
>> I just cannot work without that. All of my working style is adapted to
>> having that option.
>
> There's no reason you can't do that in zsh, but you're going to have
> some potential issues.  I've written about this in a zsh-users thread
> within the last couple of months.
>
> Copy-pasting from that thread ...
>
> 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.  (You can also do this
> by "fc -p" before invoking the editor, now that I think of it.)
>
> 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 trailing 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.
>
> Something I forgot to mention in that other thread is that the zsh
> history file is stored in what's called "metafied" format.  Mikael
> Magnusson posted an "unmetafy.c" program back in 2015 which you should
> be able to find by a search of the zsh-users archives (subject: "Read
> file with escaped newlines into array").

Yes, I'm aware of the multi-write issues. That's why I'm setting
HISTFLE= in bash, which corresponds to SAVEHIST=0. I even plan to add
SAVEHIST=0 to my .zshrc. I never want my curated files to be overwritten.

I think I need to clarify that my history_edit bash function does not
edit the history file. By writing it to a temp file, clearing and
reading that file, I edit the _local_ history of the shell I'm currently
in, and other shells are unaffected, which is also important to me.
In fact, I mostly have at least 5 open shells. That's why I added the
.$$ (PID of the shell) to the temp filename, so I can even do
history_edit in all shells without interfering.

I only edit the history files when I do my curating. As my histories are
fairly mature, this does not occur very often.

  reply	other threads:[~2020-05-20  0:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 15:52 Markus Näher
2020-05-19 18:28 ` Roman Perepelitsa
2020-05-19 20:22   ` Markus Näher
2020-05-19 22:58     ` Bart Schaefer
2020-05-20  0:13       ` Markus Näher [this message]
2020-05-20  0:23       ` Markus Näher
2020-05-19 23:03     ` Daniel Shahaf
2020-05-19 23:17       ` Bart Schaefer
2020-05-21  3:37       ` Daniel Shahaf
2020-05-19 22:33 ` Bart Schaefer
2020-05-20  0:13   ` Markus Näher
2020-05-20  4:15     ` Bart Schaefer
2020-05-20  9:38       ` Markus Näher
2020-05-21  1:05         ` Bart Schaefer
2020-05-20 23:53       ` Bart Schaefer

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=13178bd5-7b89-19a2-240f-f1886d2ffd2a@gmx.net \
    --to=markus.naeher@gmx.net \
    --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).