Re: Problems with history

Perry Smith <[email protected]> Mon, 15 Dec 2025 18:23:19 -0600
Newsgroups gmane.comp.shells.zsh.user
Message-ID <[email protected]>
I figured it out.  Note to Mark: my “login file” is my .zlogin file — and that’s the key.  It is read at login time but not by an interactive subshell.

If I do normal login / commands / logout I’m ok.  But I often drop into an interactive subshell because I’m going to change my path temporarily or something similar.  In that case, my .zlogin is not read but /etc/zshrc is read which sets HISTFILE, HISTSIZE, and SAVEHIST.  In particular SAVEHIST to 1000.  Then I exit the subshell and my .history file gets truncated to 1000.

It takes a little extra work but now if I start a login shell it gets just 1000 lines of history.  If I then exit my original shell before this new shell, the new shell leaves last and thus truncates the history file short at roughly 1000 lines with no shells left running.

I goofed — trying to minimize what is done with each shell.  The key is “history” is part of interactive — not login.

Thak you for your time

> On Dec 15, 2025, at 14:37, Bart Schaefer <[email protected]> wrote:
> 
> On Mon, Dec 15, 2025 at 8:18 AM Perry Smith <[email protected] <mailto:[email protected]>> wrote:  
>> 
>> /bin/zsh —version reports zsh 5.9 (arm64-apple-darwin25.0)
>> /opt/homebrew/bin/zsh —version reports zsh 5.9 (arm-apple-darwin22.1.0)
>> I’m assuming Terminal uses /bin/zsh
> 
> You could `print $ZSH_PATCHLEVEL` from the PS1 prompt to confirm
>  
>> When is the history file read in?
> 
> Pretty much the last thing before the prompt is printed, definitely after all the startup files are read UNLESS one of those files contains an "fc" or "history" command.
>  
>> Does setting HISTSIZE or SAVEHIST cause the current history list to get truncated?
> 
> HISTSIZE truncates the shell's internal history list, yes.  SAVEHIST won't kick in until the history is written back to HISTFILE.
>  
>> Is there any other things I should check?
> 
> As an addenda to Mark Reed's comments, you could try printing the values of the history variables in your .zlogout file (follow that with a `sleep` so you have a chance to see the output).