zsh-workers
 help / color / mirror / code / Atom feed
From: "Markus Näher" <markus.naeher@gmx.net>
To: zsh-workers@zsh.org
Subject: Re: Feature Request: fc -C to clear history and reset counter
Date: Wed, 20 May 2020 11:38:44 +0200	[thread overview]
Message-ID: <2ca16a5c-a1e9-904d-f3f6-bf785ab00343@gmx.net> (raw)
In-Reply-To: <CAH+w=7az4bgJ7mQM1iscajMh1+HjH6mR6wm+eiiV4Ly6=uM-zw@mail.gmail.com>

On 20.05.20 06:15, Bart Schaefer wrote:
> On Tue, May 19, 2020 at 5:27 PM Markus Näher <markus.naeher@gmx.net> wrote:
>
>> 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.

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.



> 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.

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.

You wrote that pop will save back the project history file. That's also
something I'd like to prevent. The project history files are even more
important to never be overwritten than the "default" history file in ~.

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

Here is my usage pattern:

As I wrote, I rarely add commands to my history file(s). But I do
history_edit very, very, very often.

I'm a lazy person, especially on the keyboard. I'd like to type as few
as possible. And I also like a static working environment. Not static
forever, but static while I'm in a specific task.

To achieve the laziness and staticness, I use (or abuse if you want) the
history-related behavior of the shell:
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).
I even have grouped the entries in my history files by comments.

I have lots of regular tasks to do. When working on a project. I mostly
have multiple shells open. Let's say it is a development project and I'm
running it locally for testing my new stuff. This is a simplified example:
Shell 1 is for build/deploy/run, shell 2 for searching things in the
logs, shell 3 for other monitoring stuff, ...

I do more things than just cd /path/to/project and load the project
history. **In every shell, the first thing I do is history_edit and
rearrange the order of the entries so that the commands I need for this
task are at the bottom.**
This way, I always have the needed commands directly at hand.
I only need to do <cursor up><enter>, check the output, and if I'm happy
with it, I'll do <up><up><enter>, and so on. The leading blanks ensure
that e.g. the second last command is always the same within this shell
(locally static).

This rearrangement of the history order is BTW a reason why I can't use
shared histories.

Of course, I'm also doing new things while working in a project. Often,
I'll have to try different variations of a command until I get the
desired result. I'm doing that **without** leading blank, so the
commands **are** added to the "local" history. After that, I do
history_edit again to eliminate all the failed attempts an only keep the
successful final one. Sometimes at the bottom, sometimes I move it up a
few lines. This gives me shorter <up>...<up><enter> sequences.
And sometimes I add this new command to my curated history.

**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.**



> 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.

I have many multi-liners in my histories, but of course they all are
converted to one-liners with semicolons. In bash, if you execute a
multi-liner and do <cursor up> afterwards, you already have it
converted. I just tested it ... zsh keeps it multilined. It's definitely
easier to read, but for my purpose, I will need to convert them
manually. That's OK for me.

  reply	other threads:[~2020-05-20  9:39 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
2020-05-20  9:38       ` Markus Näher [this message]
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=2ca16a5c-a1e9-904d-f3f6-bf785ab00343@gmx.net \
    --to=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).