Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How zsh stores history? History file format

Tags:

zsh

oh-my-zsh

I am not sure if I fully understand how zsh stores its history. Example line:

: 1458291931:0;ls -l

I guess we have here:

  • timestamp: 1458291931
  • command: ls -l

but what this mystical 0 in between means?

like image 886
NowNick Avatar asked Jun 22 '16 07:06

NowNick


1 Answers

This is the so-called *extended history format, which is enabled by the EXTENDED_HISTORY shell option. The second number (the "mystical 0") is the duration of the command. "0" either means that the command finished quickly or - depending on your settings - that the duration is not saved. If either of the shell options INC_APPEND_HISTORY or SHARE_HISTORY is enabled (you can check this with setopt | grep -E '^(incappend|share)history$'), then zsh will write the history entry to the history file immediately after confirming the command. The duration will be saved as "0" in that case.

If you want to make use of the duration metric while still saving the history to file during shell sessions, you can set the option INC_APPEND_HISTORY_TIME, in which case zsh will wait for command completion before writing the entry. Obviously this will otherwise behave like INC_APPEND_HISTORY.

Note: only one of the options INC_APPEND_HISTORY, INC_APPEND_HISTORY_TIME and SHARE_HISTORY should be active

like image 156
Adaephon Avatar answered Oct 21 '22 01:10

Adaephon