zsh-users
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Perry Smith <pedz@easesoftware.com>
Cc: zsh-users@zsh.org
Subject: Re: .zsh_history
Date: Fri, 14 Apr 2023 09:51:15 -0500	[thread overview]
Message-ID: <CAMP44s0bs6Go8twZL-02ZHCD0+68ajgdrAj46t+WtAL5pEneVQ@mail.gmail.com> (raw)
In-Reply-To: <81609CF4-42DA-4E0F-A6E5-C5D58578B4F7@easesoftware.com>

On Sat, Apr 8, 2023 at 11:17 AM Perry Smith <pedz@easesoftware.com> wrote:
>
> I don’t have anything special set up other than setting HISTFILE, HISTSIZE=2097152, and SAVEHIST=1048576.  I also have histignoredups and histignorealldups on.
>
> The reason for the huge numbers is partially due to some confusion I had (see below) but basically I want to save unique commands that I did for very long periods of time so I don’t need to figure them out again.

I do the same, but hopefully you are not relying on zsh to do that,
because you have to grep the history file yourself.

> I’m on macOS and they have this thing for “sessions” which I’ve turned off now (a few weeks ago).  The reason is that the session history files are limited to two weeks and so commands I did long ago are getting deleted and my .zsh_history file was only growing to be about 1000 lines.
>
> My question is, if I start multiple terminals and run various commands and eventually they each log out or exit, I’m wondering what happens to the .zsh_history file.  Does the last shell to exit rewrite the file using its own history which (I’m guessing) is the contents of .zsh_history when the shell started up plus the commands that were executed in that shell?  This would overwrite all the commands done in the other shells that have just exited.

It writes all the current history of the shell (`fc -l 0`), but by
default APPEND_HISTORY is on, so it would append the current history
to the file. So in practice the history is not overridden.

But is this realistic? Do you actually have more than 1048576 lines in
your history? What is $HISTCMD?

> Alternatively, the shell could re-read .zsh_history at the time it is exiting and append the commands that were executed within that shell and write the result out — thus preserving the commands done by other shells.

That's exactly what it does (unless you set NO_APPEND_HISTORY).

Cheers.

-- 
Felipe Contreras


      parent reply	other threads:[~2023-04-14 14:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-08 16:16 .zsh_history Perry Smith
2023-04-08 16:53 ` .zsh_history Roman Perepelitsa
2023-04-08 17:23   ` .zsh_history Ray Andrews
2023-04-08 17:27     ` .zsh_history Roman Perepelitsa
2023-04-08 17:35       ` .zsh_history Perry Smith
2023-04-08 17:54       ` .zsh_history Ray Andrews
2023-04-14 14:36         ` .zsh_history Felipe Contreras
2023-04-14 15:27           ` .zsh_history Ray Andrews
2023-04-15  4:49             ` .zsh_history Felipe Contreras
2023-04-15 15:29               ` .zsh_history Ray Andrews
2023-04-15 19:47                 ` "Pull just the text of a single command" (was Re: .zsh_history) Bart Schaefer
2023-04-15 22:47                   ` Ray Andrews
2023-04-15 23:26                     ` Bart Schaefer
2023-04-16 15:53                       ` Bart Schaefer
2023-04-16 16:37                         ` Ray Andrews
2023-04-16 19:24                         ` Ray Andrews
2023-04-16  7:38                 ` .zsh_history Roman Perepelitsa
2023-04-16 14:53                   ` .zsh_history Ray Andrews
2023-04-16 15:28                     ` .zsh_history Bart Schaefer
2023-04-16 15:29                     ` .zsh_history Roman Perepelitsa
2023-04-14 14:28     ` .zsh_history Felipe Contreras
2023-04-14 15:18       ` .zsh_history Ray Andrews
2023-04-14 14:00   ` .zsh_history Felipe Contreras
2023-04-14 14:51 ` Felipe Contreras [this message]

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=CAMP44s0bs6Go8twZL-02ZHCD0+68ajgdrAj46t+WtAL5pEneVQ@mail.gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=pedz@easesoftware.com \
    --cc=zsh-users@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).