zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Markus Näher" <markus.naeher@gmx.net>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Feature Request: fc -C to clear history and reset counter
Date: Tue, 19 May 2020 21:15:55 -0700	[thread overview]
Message-ID: <CAH+w=7az4bgJ7mQM1iscajMh1+HjH6mR6wm+eiiV4Ly6=uM-zw@mail.gmail.com> (raw)
In-Reply-To: <a05e5fde-a872-5a1e-c495-9f1a36e526ed@gmx.net>

On Tue, May 19, 2020 at 5:27 PM Markus Näher <markus.naeher@gmx.net> wrote:
>
> On 20.05.20 00:33, Bart Schaefer wrote:
> >
> > So you can simulate bash's "history -c" by "fc -P;fc -p", with some
> > appropriate extra arguments to manipulate history sizes and file
> > locations.
>
> I would not call any of these concepts superior to the other. Different
> people just prefer different things.

As you like. I just think it's easier to create multiple independent
saved histories with "fc -p" than with "history -c" plus modifying a
bunch of global variables.

> I've read about the push/pop feature, but I'm more the "throw away the
> old stuff and start over" kind of guy. I'll never need to pop. :-)

You'd pop just to keep the shell from continually consuming more
memory.  Truly clearing the history is pop followed by push; pushing
is just hiding the old history.

> Can you give me some advice about the "appropriate extra arguments" you
> wrote about ? My goal is to really start over, having nothing left from
> the previous history.

I don't know your exact use pattern, but let's say for the sake of
example that you have 100 commands in your never-overwritten
~/.histfile, but you never want to save more than 20 commands in a
given per-project history file.  On entering the shell, your 100 saved
commands get loaded in.

Now you're entering your project, which has its history in
$PWD/.project_history (for example).  If for example upon "cd" into
the project directory, you run
  fc -p $PWD/.project_history 20 20
that will load the .project_history file and automatically set the
HISTFILE, HISTSIZE, and SAVEHIST variables so that when you next
execute "fc -P" (presumably, when leaving the directory again) it will
save the most recent 20 commands back to the .project_history file,
reset the history to those original 100 commands, and restore the old
values of the variables.

You can modify this behavior by passing only the file name, or the
file name and one number, or none of those.

On Tue, May 19, 2020 at 5:29 PM Markus Näher <markus.naeher@gmx.net> wrote:
>
> I'm currently experimenting with zsh, and I copied my ~/.bash_history to
> ~/.histfile. At least, zsh can read the history in plaintext.

Careful with that, too.  Bash stores its history file as essentially a
shell script, and loads it by parsing it as script input but skipping
execution.  Zsh stores its history file more like text intended to be
consumed by the "read" builtin, and loads it straight back into the
internal history structure without passing it through the shell
language parser.  That means that multi-line commands in the bash
history will become multiple, separately-numbered events in the zsh
history.  If all your curated events are one-liners, this won't
matter.

  reply	other threads:[~2020-05-20  4:16 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
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 [this message]
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='CAH+w=7az4bgJ7mQM1iscajMh1+HjH6mR6wm+eiiV4Ly6=uM-zw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=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).