1

When I switch VPN or close my laptop, my ssh connection breaks - which is acceptable. BUT I want to be reminded what I was doing when it was last running (often I'm using rsync to move files around).

But when I execute history those commands don't appear. While I don't know exactly when zsh commits the history, it seems like it doesn't write it to .zsh-history as soon as the command is invoked.

Does ZSH have a way to add commands to .zsh-history immediately?

Other info

I vaguely recall setting a variable that shares history between tabs, but I can't find it (apparently that's not enough anyway). This returns nothing:

env | grep HIST

1 Answers1

2

This returns nothing:

env | grep HIST

Well, no, for two reasons:

  • If it were controlled by an environment variable, but that variable hasn't been set, then you won't find it in the environment.
  • It's not actually an env var that controls this, but a shell option.

Zsh has three relevant shell options for this : INC_APPEND_HISTORY, INC_APPEND_HISTORY_TIME and SHARE_HISTORY. Note that all three are mutually exclusive: You should set only one of them, and not the others.

I vaguely recall setting a variable that shares history between tabs

It sounds like you want SHARE_HISTORY. In that case, add this to your .zshrc file:

setopt sharehistory  # uppercase and underscores are optional

In future, if you want to check for a shell option on the command line, you can do this:

% set -o | grep hist
noappendhistory       off
nobanghist            off
cshjunkiehistory      off
extendedhistory       off
histallowclobber      off
nohistbeep            off
histexpiredupsfirst   off
histfcntllock         on
histfindnodups        off
histignorealldups     on
histignoredups        off
histignorespace       off
histlexwords          off
histnofunctions       off
histnostore           off
histreduceblanks      off
nohistsavebycopy      off
histsavenodups        on
histsubstpattern      off
histverify            off
incappendhistory      off
incappendhistorytime  off
sharehistory          on
%