Search code examples
zshzshrc

How do you share zsh history between multiple machines?


I have a setup I'm pretty happy with for sharing my configuration files between machines, but I find that I often want to search back in zsh (Ctrl + R) and I can't remember which machine I typed the command on. Ideally I'd like this to search a canonical de-duped list of previous commands from any of my machines. Given that I sometimes work on these machines concurrently and without a network connection, what's a sensible way of merging history files and keeping everything in sync?


Solution

  • Hmm, I guess you could identify your accounts somehow... then you could do the following:

    • modify your .zshrc to catenate the history of the OTHER accounts from dropbox or SCM with the current history IF this is the first zsh launched on the current computer
    • then sort the entries with -n (sort by timestamp)
    • I guess zsh would remove the duplicates if you have setopt HIST_SAVE_NO_DUPS

    Then you need to trap shell exit, and copy the existing history to the dropbox/SCM/whatever shared place.