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=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16708 invoked from network); 19 May 2020 22:59:11 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 19 May 2020 22:59:11 -0000 Received: (qmail 18471 invoked by alias); 19 May 2020 22:59:02 -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: 45853 Received: (qmail 3762 invoked by uid 1010); 19 May 2020 22:59:02 -0000 X-Qmail-Scanner-Diagnostics: from mail-oo1-f53.google.com 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(209.85.161.53):SA:0(-1.9/5.0):. Processed in 3.028823 secs); 19 May 2020 22:59:02 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.161.53 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=vJHYocy5XA4CWdfwTp8dT61hqZAsvE0Ek8kslFVriuo=; b=Om0Yt9dd4G1uW+vJRIPGuphZq8wEBD+W1Lvpc3tU1Nzn4qgWE02peYExyXCqA6yRy9 PmHHjlXVbmM3TvZErTEmgmkuI6f9B0CsMG4YCC1wh/eBWEwtDWr3R/GWIc2z8QYhX3Xb Fy/Q5FE8glSQmQORcVFFEmnCz0HkIHYMvyS1XxuMTURVaBKvZExQ5PLmnsOLxR4n/Sdv DadYLHJya5nl4i+Jz9GFWcNbh056RVHCS6XK5wrx3EWwurXQ/xt7PM6vMdedmKBLrbjk g5Qbe7ELsOGU3BmprrfcWoR7dUM9ABaHN1gwVMlFBe3J1m66EOVmJMHjETh/So7fUTiM 9Vig== X-Gm-Message-State: AOAM533gOh9WW41lwmrSi86TLfnV6Z9ALVTrS124TF+bjZH5bPXPRwgA rpK+hMj7X9yH/2oFosERajkvAs0Q256RW+j/07dr/w== X-Google-Smtp-Source: ABdhPJxDLMjZ1nfTJcTpdLtplzXj4h5Fhh5YPStkbVMOREIpSWJ1vj2Hqa0FFlJt9f1iQp76Lyo1le38iMewQFCyXzk= X-Received: by 2002:a4a:de89:: with SMTP id v9mr1173320oou.29.1589929106239; Tue, 19 May 2020 15:58:26 -0700 (PDT) MIME-Version: 1.0 References: <48e95c73-3a98-a4c2-7e0c-badf8544b4f2@gmx.net> <670c0cf4-cf73-22d8-1ac9-dfb392521b99@gmx.net> In-Reply-To: <670c0cf4-cf73-22d8-1ac9-dfb392521b99@gmx.net> From: Bart Schaefer Date: Tue, 19 May 2020 15:58:15 -0700 Message-ID: Subject: Re: Feature Request: fc -C to clear history and reset counter To: =?UTF-8?Q?Markus_N=C3=A4her?= Cc: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 19, 2020 at 1:22 PM Markus N=C3=A4her w= rote: > > 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").