zsh-workers
 help / color / mirror / code / Atom feed
* zero elapsed time in history with certain preexec functions
@ 2007-12-25 19:07 Michael Kaminsky
  2007-12-29 18:33 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kaminsky @ 2007-12-25 19:07 UTC (permalink / raw)
  To: zsh-workers

I sent this message to zsh-users in August, but didn't see any response.
In case it fell through the cracks, I'm re-sending to zsh-workers.  Can
anyone say if this is a bug?  Is there a fix or work-around?

Note:  I re-tested everything below with "zsh -f" and the behavior is the
same.  After "zsh -f" you need to "setopt" the options list in the first
example: extendedhistory histignoredups histignorespace histnostore.

Please CC me on any responses as I'm not on the list.

Thanks,

Michael

-------------------------------------------------

I use zsh's preexec function to set the title of my terminal, similar to
many of the examples posted online.  After defining preexec, however, I
noticed that zsh wasn't recording the duration of commands anymore.
After much experimentation, I believe I've come up some simple examples
to illustrate this behavior:

   $ zsh --version
   zsh 4.3.4 (i686-pc-linux-gnu)
   $ setopt|grep hist
   extendedhistory
   histignoredups
   histignorespace
   histnostore
   $ unfunction preexec
   $ sleep 2
   $ fc -ldD |tail -1
   12004  11:16  0:02  sleep 2

(so far, so good)

   $ function preexec { echo $ZSH_VERSION }
   $ sleep 2
   4.3.4
   $ fc -ldD |tail -1
   4.3.4
   12014  11:18  0:02  sleep 2

(still good, but...)

   $ function preexec { echo $ZSH_VERSION[1] }
   4.3.4
   $ sleep 2
   4
   $ fc -ldD |tail -1
   4
   12016  11:20  0:00  sleep 2

It appears that subscripting a variable (or indexing into a zsh array)
inside of the preexec function causes zsh not to record the elapsed
time/duration of the command.  There may be other actions that trigger
this behavior.  Another quick example:

   $ function preexec() { echo $1 }
   $ sleep 2
   sleep 2
   $ fc -ldD |tail -1
   fc -ldD |tail -1
   12040  11:25  0:02  sleep 2

(but...)

   $ function preexec() { echo ${(z)1} }
   function preexec() { echo ${(z)1} }
   $ sleep 2
   sleep 2
   $ fc -ldD |tail -1
   fc -ldD | tail -1
   12044  11:27  0:00  sleep 2


Any ideas?

Michael


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

* Re: zero elapsed time in history with certain preexec functions
  2007-12-25 19:07 zero elapsed time in history with certain preexec functions Michael Kaminsky
@ 2007-12-29 18:33 ` Bart Schaefer
  2008-01-03 17:23   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2007-12-29 18:33 UTC (permalink / raw)
  To: zsh-workers

On Dec 25,  2:07pm, Michael Kaminsky wrote:
}
} It appears that subscripting a variable (or indexing into a zsh array)
} inside of the preexec function causes zsh not to record the elapsed
} time/duration of the command.

A time is recorded, but it's the wrong time.

The following seems to fix it, but someone more familiar with this part
of the history mechanism should check my work: 

Index: Src/hist.c
===================================================================
diff -c -r1.31 hist.c
--- Src/hist.c	26 Nov 2007 17:38:13 -0000	1.31
+++ Src/hist.c	29 Dec 2007 18:24:06 -0000
@@ -826,7 +826,7 @@
     }
     chwordpos = 0;
 
-    if (hist_ring && !hist_ring->ftim)
+    if (hist_ring && !hist_ring->ftim && !strin)
 	hist_ring->ftim = time(NULL);
     if ((dohist == 2 || (interact && isset(SHINSTDIN))) && !strin) {
 	histactive = HA_ACTIVE;


(Revision numbers are from my local CVS repository and bear no relation
to the Sourceforce repository.)

-- 


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

* Re: zero elapsed time in history with certain preexec functions
  2007-12-29 18:33 ` Bart Schaefer
@ 2008-01-03 17:23   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2008-01-03 17:23 UTC (permalink / raw)
  To: zsh-workers

On Sat, 29 Dec 2007 10:33:07 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Dec 25,  2:07pm, Michael Kaminsky wrote:
> }
> } It appears that subscripting a variable (or indexing into a zsh array)
> } inside of the preexec function causes zsh not to record the elapsed
> } time/duration of the command.
> 
> A time is recorded, but it's the wrong time.
> 
> The following seems to fix it, but someone more familiar with this part
> of the history mechanism should check my work: 

Looks entirely reasonable, without having done more than a cursory
look.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2008-01-03 17:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-25 19:07 zero elapsed time in history with certain preexec functions Michael Kaminsky
2007-12-29 18:33 ` Bart Schaefer
2008-01-03 17:23   ` Peter Stephenson

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