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

Saving commands from a session



In addition to saving commands in .zhistory, I like to save commands
by session, so I can save and later search the sequence of commands I
executed at a particular time.  In order to do this, in .zlogout I
compared all commands in history against the date and time of the
first command saved:

# Get the date and time of the first command in the shell history.
fc -lin -$HISTCMD -$((HISTCMD-1)) | read d t cmd

# Ignore all commands that have the same date and time.
# They were read in when the shell started.
fc -lin -$HISTCMD | grep -v "^$d $t" >> $outfile

I was never terribly impressed by the elegance of this solution, but
it worked, more or less (I believe it could drop the first command or
two I entered if they happened to have the same date and time as the
start of the shell).

However, I recently started using

setopt EXTENDED_HISTORY

and this has the effect of keeping the original date and time the
command was executed in .zhistory, so when the historical commands are
read into the shell, they no longer all have the same date and time.

Is there a more elegant way to save only those commands that have been
executed in this instance of the shell?

Thanks in advance,
  Vin Shelton



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