From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24622 invoked from network); 20 May 2020 00:14:37 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 20 May 2020 00:14:37 -0000 Received: (qmail 6045 invoked by alias); 20 May 2020 00:14:31 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45858 Received: (qmail 10807 invoked by uid 1010); 20 May 2020 00:14:31 -0000 X-Qmail-Scanner-Diagnostics: from mout.gmx.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25814. spamassassin: 3.4.4. Clear:RC:0(212.227.17.22):SA:0(-2.7/5.0):. Processed in 4.384522 secs); 20 May 2020 00:14:31 -0000 X-Envelope-From: markus.naeher@gmx.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at gmx.net designates 212.227.17.22 as permitted sender) X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Subject: Re: Feature Request: fc -C to clear history and reset counter To: zsh-workers@zsh.org References: <48e95c73-3a98-a4c2-7e0c-badf8544b4f2@gmx.net> <670c0cf4-cf73-22d8-1ac9-dfb392521b99@gmx.net> From: =?UTF-8?Q?Markus_N=c3=a4her?= Autocrypt: addr=markus.naeher@gmx.net; 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 Message-ID: <13178bd5-7b89-19a2-240f-f1886d2ffd2a@gmx.net> Date: Wed, 20 May 2020 02:13:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:B4IPPZ30CM/NpnIgrpA7/6pAYJFRBJvhLMLFGdeA5LatLSQvNKZ j/LY9/6teiVe1QB2EEa2X2dhi1h6nGl3R5fjGF6ljwTwJ3csTvdaJjmXJT46pQMjTDB7E+V 2rOBqKPpDdri3CsNYHRsmC/yJgzHWyOnixzoKWkizSbmjbziF+r3Vdc8BpWQGPpfNFegi2O 2eFYrfql0TcjeD30uj8Xg== X-UI-Out-Filterresults: notjunk:1;V03:K0:skfDp1plvF8=:ioE3iBcH0tk7ANnY+D0Wkh ArNybmxWKj4WCrZVpBbqqkWl62My2giPRA6dSZWFzY0HgQwv2nsVmba7ES4uPmS01SLJwlCmH 8HGPKzylZJPtESNxcj2mmBrBd5uHzL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+/ySW23Qq0Z6y0dVv2VFs+BwbW2FeFvEEOEsRzD6m+ctJ3ez0JdGRvHUdnSsT9jbhhwQ1Xq t2ytAb+suB6x3sLNo On 20.05.20 00:58, Bart Schaefer wrote: > On Tue, May 19, 2020 at 1:22 PM Markus N=C3=A4her 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=3D0 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=3D in bash, which corresponds to SAVEHIST=3D0. I even plan to add SAVEHIST=3D0 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.