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

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

On Wed, May 20, 2020 at 2:39 AM Markus Näher <markus.naeher@xxxxxxx> wrote:
> Keeping the shell from continually consuming more memory is one of the
> reasons why I hesitate to use push when I know I never will pop.

It's harmless to pop when nothing has been pushed, so you can just do

history_c() { fc -P ; fc -p }

Then stick that in your current bash usage pattern wherever you have
"history -c" and go on your merry way.  You'll always have exactly one
extra "depth" of history.

However, there is probably more you can do if you're interested in
digging into it.

> My usage pattern is even more complex. I's heavily based on making a
> difference between the commands loaded from my curated history files and
> the "local" or "transient" history while running the shell. I put way
> more effort in preparing things, then using them will be easier.

The "fc -I" (dash capital eye, for those in sans serif) can be used to
select only the commands that were entered interactively, if that is
helpful.  That is, it excludes any commands read from a history file,
whether at startup, or with "fc -R filename" or "fc -p filename".
(There is not presently an inverse of this.)

> You wrote that pop will save back the project history file. That's also
> something I'd like to prevent.

This can be done by changing/unsetting HISTFILE, or zeroing SAVEHIST,
after "fc -p".

> **My curated history files are sacred. No one but me should write them.**

Why not keep them "chmod -w" and only make them writable during editing?

> All of the entries in my history files start with a blank. So a command
> never gets duplicated to the bottom when I recall it, but recalling
> works despite the blank. (The igonoredups/ignoreboth in bash seems to
> work only on consecutive duplicates).

Zsh additionally has histignorealldups, but I don't think it works the
way you want.

However, you might take a look at the zshaddhistory hook function, and
the HISTORY_IGNORE variable.

> **I hope this makes clear that history_edit is a completely normal thing
> for me to do. Sometimes every few minutes. Having to deal with push/pop
> will make this much more complicated as I have to keep track if and how
> many times I have pushed.**

Does this mean that you are always clearing the history, editing the
file, and then reloading from the file?  Thus in each of the two or
three shells that you start to enter a project, your edit begins from
whatever you saved in the previous shell?

I was thinking about what Daniel said about using vared on the
history, to edit it within the shell rather than in a disk file.
There might be a way to simulate that in shell code, using "fc -p" to
install the edited events.  Hmm.

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