Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature Request: fc -C to clear history and reset counter



On Tue, May 19, 2020 at 5:27 PM Markus Näher <markus.naeher@xxxxxxx> 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@xxxxxxx> 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.



Messages sorted by: Reverse Date, Date, Thread, Author