Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature Request: fc -C to clear history and reset counter
- X-seq: zsh-workers 45858
- From: Markus Näher <markus.naeher@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Feature Request: fc -C to clear history and reset counter
- Date: Wed, 20 May 2020 02:13:48 +0200
- Autocrypt: addr=markus.naeher@xxxxxxx; keydata= mDMEXi1PPhYJKwYBBAHaRw8BAQdA5mC+PjCn5mz47ngBjY5+8r9YeloIjigNtKiHPaSlvAW0 JE1hcmt1cyBO5GhlciA8bWFya3VzLm5hZWhlckBnbXgubmV0PoiWBBMWCAA+FiEEVnCH2Hg5 cG3BryclHHm+zifSIesFAl4tTz4CGwMFCQlmAYAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AA CgkQHHm+zifSIeuzrQEA1dCwtJCeDcc20kPViqt5ekqidR3gpW59obGT+xvt5pgBAMyawHqH pa+PH4Mr6+9Sh/6u/yI01WwvGAK/m2CJT6sOuDgEXi1PPhIKKwYBBAGXVQEFAQEHQO2mlMor hTTZq9WUdRZMc2NhGaapZ9ZyaQesF23tQGU7AwEIB4h+BBgWCAAmFiEEVnCH2Hg5cG3Brycl HHm+zifSIesFAl4tTz4CGwwFCQlmAYAACgkQHHm+zifSIes1TQEAs2SYqsBfB++PKJIFcZdh 2xkH5YBaSN5L8hepGnb8mhgBAKZqF4jEppwZt0/c92ymZu2EssLB2WIOx+V6LazlYMkF
- In-reply-to: <CAH+w=7ZDmfTpWH_Z1NQ=iCR9FxF=FTUF5Sigr7NAD_PtiJ4OkQ@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <48e95c73-3a98-a4c2-7e0c-badf8544b4f2@gmx.net> <CAN=4vMpErMFeYaOt0bhuUefe-xgA+0gzRo-y7qXKXe7MS5GaSQ@mail.gmail.com> <670c0cf4-cf73-22d8-1ac9-dfb392521b99@gmx.net> <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@xxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author