Reputation:
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?
Upvotes: 15
Views: 16076
Reputation: 9
I use the command below:
ssh [email protected] cat ~/.zsh/.zhistory | cat ~/.zsh/.zhistory - | sort | uniq | tee ~/.zsh/.zhistory | ssh [email protected] cat \> ~/.zsh/.zhistory
Upvotes: -1
Reputation: 1935
You could have a NFS mount point for the involved machines with the .zsh_history in it. Each machine would need the HISTFILE env var set to that file path in the NFS.
HISTFILE env var is compulsory, since ZSH does not accept a symlink, and it would be replaced by a file using the last version of the symlink target.
I have not tested what is said above, since my setup is between VM's using OSX and Parallels shared folders. Hence, with NFS the integrity (order?) of the file could be something to consider, also VS the Dropbox solution.
Not sure, something like https://gist.github.com/elim/f77e3e9f06b6f8a5e788 could be used to fix versions to be merged...
Upvotes: 0
Reputation: 6934
I wrote this plugin for oh-my-zsh:
An Oh My Zsh plugin for GPG encrypted, Internet synchronized Zsh history using Git https://github.com/wulfgarpro/history-sync
Upvotes: 6
Reputation: 134038
Hmm, I guess you could identify your accounts somehow... then you could do the following:
Then you need to trap shell exit, and copy the existing history to the dropbox/SCM/whatever shared place.
Upvotes: 1