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

Re: Editing history stack during runtime?

On Mar 3,  1:25pm, Richard Hartmann wrote:
} On Sat, Mar 1, 2008 at 1:59 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} >  "The history accumulated since I logged in" *includes* the history
} >  read from the history file at shell startup.
} Hmm, now that I think about it, this _does_ make sense. Matter of fact,
} nothing else would. I will probably try and hack something together that
} uses a custom variable to store invocation time of the shell

Hmm.  Actually you can get away with discarding all history entries with
history number <= than the original value of SAVEHIST (from *before* the
assignment SAVEHIST=$HISTSIZE in the edit_history function).  Assuming
that you haven't changed SAVEHIST since the last time the history file
was written, of course -- if you change SAVEHIST a lot you'll have to do
more work to get the startup-time maximum history number.

It's not particularly easy to discard those entries, though.  Probably
the best way is to put the "fc -W" in a subshell and truncate the history
there, like so:

      # Needs recent-enough zsh to have HISTCMD
      if ((HISTCMD > histcmd_at_startup))
      then HISTSIZE=$((HISTCMD - histcmd_at_startup))
      fc -W

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