ZSH Gem #15: Shared history

Posted by | Comments (0) | Trackbacks (0)

If one thing annoys me then it's when the shell history doesn't handle multiple simultaneous shell sessions properly. Once you close a shell instance, its complete history is written to the history file. And when you close the second instance, it writes its whole history in one go, too. The result is that I have to go through all history entries of the second instance to come to the last entry of the first one (if they're not already deleted because the history of the second shell was longer than the maximum history size or because the shell is configured to replace the whole history instead of appending new entries).

But as you might have guessed: ZSH has an option for this:

setopt inc_append_history

With this option all history items remain in chronological order even when multiple ZSH instance are open at the same time. This is achieved by writing entries directly into the file instead of dumping the whole history when the shell exits.

But that's not all. There is an even more advanced option:

setopt share_history

This option does not only write history entries directly to the history file, it also shares the current history file between all sessions. That means that a command executed on shell #1 also appears as the last command in shell #2 as soon as shell #2 redraws its prompt. This is sometimes not what you want (in those cases you can disabled SHARE_HISTORY) but often it's a great thing as it makes working with more than one shell session a lot easier. You don't always have to remember on which shell you typed which command. Instead you can use any of them as they all share the same history.

SHARE_HISTORY also writes time stamps of when the command was executed and how long it took to the history file (otherwise activated with the option EXTENDED_HISTORY). I can only recommend using this option

Read more about shared history:

Trackbacks

No Trackbacks for this entry.

Comments

No comments have been submitted yet. Be the first!

Write a comment:

HTML-Tags will be converted to Entities.
Textile-formatting allowed
Standard emoticons like :-) and ;-) are converted to images.
Design and Code Copyright © 2010-2014 Janek Bevendorff Content on this site is published under the terms of the GNU Free Documentation License (GFDL). You may redistribute content only in compliance with these terms. tweetbackcheck