Zsh Mailing List Archive
Messages sorted by:
Re: Saving commands from a session
- X-seq: zsh-users 19735
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Vin Shelton <acs@xxxxxxxxxxxxxxxxxxxx>
- Subject: Re: Saving commands from a session
- Date: Mon, 12 Jan 2015 18:19:36 +0100
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=YOn8zwkMnzY2/qrVLFXMu9MN/XyI5mHVQxhL6t5ntf8=; b=zwWlU6Tj+j6PA75tJCLjAZ+fixIuaqJ8OVJI48VY3oHTjpoI37YI18BEWgUSmBq80M Kyrrs0vbd7K/ueSIeSdql/sgN6qJAOl5mGX5TVxDJDyGp6oyjldeKYO/llk1KqqB+O38 JZl9GJZRqQIFL8SHBa80C3eGujtoKn9D2vCAcXK5DCGNNx6syi07qZAl0K6dcOmQouey NZ8av1ldKyBYSo2IAqBVy7O+wAhrrchFckVNR1bZWTfDFRN/0wvaJWOFMu3HHweo1ff4 ii1eu3EAkNAUXclc4Yg+9e924/4bZ4w3VmUhcaNmKInRqV9woOFa7ufNV4l46jyC942C y5rQ==
- In-reply-to: <CACeGjnUbh2h0o2Y3Hg=_OGO79zPAx0kms=UmLCbJ4RZabXgHGA@mail.gmail.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CACeGjnUbh2h0o2Y3Hg=_OGO79zPAx0kms=UmLCbJ4RZabXgHGA@mail.gmail.com>
On Mon, Jan 12, 2015 at 6:01 PM, Vin Shelton <acs@xxxxxxxxxxxxxxxxxxxx> wrote:
> 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
Maybe you want to write out each entry incrementally from
zshaddhistory() instead? Zsh does track which history entries are
"local" and which are imported from history, but I don't believe you
can directly access this information.
Messages sorted by: