zsh-users
 help / color / mirror / code / Atom feed
* Duration not written to history file
@ 2023-10-20 12:42 Andreas Kähäri
  2023-10-20 19:49 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Kähäri @ 2023-10-20 12:42 UTC (permalink / raw)
  To: zsh-users

Good day,

When starting a fresh interactive zsh session, setting HISTFILE and
SAVEHIST and enabling the EXTENDED_HISTORY and SHARE_HISTORY options,
the duration of commands is not written to the history file:

$ setopt
interactive
monitor
shinstdin
zle
$ HISTFILE=~/history; SAVEHIST=30
$ ls
$ setopt EXTENDED_HISTORY
$ setopt SHARE_HISTORY
$ ls
history
$ cat history
: 1697804875:0;setopt
: 1697804897:0;HISTFILE=~/history; SAVEHIST=30
: 1697804902:0;ls
: 1697804914:0;setopt EXTENDED_HISTORY
: 1697804927:0;setopt SHARE_HISTORY
: 1697804928:0;ls
: 1697804930:0;cat history
$ sleep 5
$ cat history
: 1697804875:0;setopt
: 1697804897:0;HISTFILE=~/history; SAVEHIST=30
: 1697804902:0;ls
: 1697804914:0;setopt EXTENDED_HISTORY
: 1697804927:0;setopt SHARE_HISTORY
: 1697804928:0;ls
: 1697804930:0;cat history
: 1697804936:0;sleep 5
: 1697804943:0;cat history

When issuing the "fc -W" command, the duration is filled in:

$ fc -W
$ cat history
: 1697804875:0;setopt
: 1697804897:0;HISTFILE=~/history; SAVEHIST=30
: 1697804902:0;ls
: 1697804914:0;setopt EXTENDED_HISTORY
: 1697804927:0;setopt SHARE_HISTORY
: 1697804928:0;ls
: 1697804930:0;cat history
: 1697804936:5;sleep 5
: 1697804943:0;cat history
: 1697804950:0;fc -W
: 1697804952:0;cat history

Is this expected behaviour?  The equivalent of "fc -W" does not seem to
be issued by the shell at any point, not even when the session
terminates.

If this is not a bug, how should I set things up to get the duration of
commands written to the history file in a shared history setup?  Ideally
without using any hooks that runs "fc -W" after each command or similar
(that would be a hack IMHO).


Regards,
Andreas

ps. I'm currently using "zsh 5.9 (x86_64-unknown-openbsd7.4)".

-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Duration not written to history file
  2023-10-20 12:42 Duration not written to history file Andreas Kähäri
@ 2023-10-20 19:49 ` Bart Schaefer
  2023-10-20 21:39   ` Andreas Kähäri
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2023-10-20 19:49 UTC (permalink / raw)
  To: zsh-users

On Fri, Oct 20, 2023 at 5:43 AM Andreas Kähäri <andreas.kahari@abc.se> wrote:
>
> When starting a fresh interactive zsh session, setting HISTFILE and
> SAVEHIST and enabling the EXTENDED_HISTORY and SHARE_HISTORY options,
> the duration of commands is not written to the history file:

SHARE_HISTORY writes the line to the file as soon as it's accepted,
rather than waiting until the command completes, so there is no
duration available.  This does not appear to be clearly documented,
although INC_APPEND_HISTORY_TIME says:
     This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY
     are turned off.  The three options should be considered mutually
     exclusive.

> If this is not a bug, how should I set things up to get the duration of
> commands written to the history file in a shared history setup?  Ideally
> without using any hooks that runs "fc -W" after each command or similar
> (that would be a hack IMHO).

Well, hack or not, the doc for SHARE_HISTORY says:
     If you find that you want more control over when commands get
     imported, you may wish to turn SHARE_HISTORY off,
     INC_APPEND_HISTORY or INC_APPEND_HISTORY_TIME (see above) on, and
     then manually import commands whenever you need them using `fc -RI'.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Duration not written to history file
  2023-10-20 19:49 ` Bart Schaefer
@ 2023-10-20 21:39   ` Andreas Kähäri
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Kähäri @ 2023-10-20 21:39 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On Fri, Oct 20, 2023 at 12:49:52PM -0700, Bart Schaefer wrote:
> On Fri, Oct 20, 2023 at 5:43 AM Andreas Kähäri <andreas.kahari@abc.se> wrote:
> >
> > When starting a fresh interactive zsh session, setting HISTFILE and
> > SAVEHIST and enabling the EXTENDED_HISTORY and SHARE_HISTORY options,
> > the duration of commands is not written to the history file:
> 
> SHARE_HISTORY writes the line to the file as soon as it's accepted,
> rather than waiting until the command completes, so there is no
> duration available.  This does not appear to be clearly documented,
> although INC_APPEND_HISTORY_TIME says:
>      This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY
>      are turned off.  The three options should be considered mutually
>      exclusive.
> 
> > If this is not a bug, how should I set things up to get the duration of
> > commands written to the history file in a shared history setup?  Ideally
> > without using any hooks that runs "fc -W" after each command or similar
> > (that would be a hack IMHO).
> 
> Well, hack or not, the doc for SHARE_HISTORY says:
>      If you find that you want more control over when commands get
>      imported, you may wish to turn SHARE_HISTORY off,
>      INC_APPEND_HISTORY or INC_APPEND_HISTORY_TIME (see above) on, and
>      then manually import commands whenever you need them using `fc -RI'.

Thanks for the reply.  This gave me a bit more of an understanding of
how those options work.  I will probably have to revisit how I manage
the shell history in my setup.

-- 
Andreas (Kusalananda) Kähäri
Uppsala, Sweden

.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-20 21:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-20 12:42 Duration not written to history file Andreas Kähäri
2023-10-20 19:49 ` Bart Schaefer
2023-10-20 21:39   ` Andreas Kähäri

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).