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

zero elapsed time in history with certain preexec functions



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



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