Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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

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...

I use the command below:

ssh username@example.com cat ~/.zsh/.zhistory | cat ~/.zsh/.zhistory - | sort | uniq | tee ~/.zsh/.zhistory | ssh username@example.com cat \> ~/.zsh/.zhistory

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top