Keep dotfiles in sync across multiple machines
A common dotfile workflow: keep your dotfiles in Git(Lab/Hub), clone the repo into any new machines' home directory, and then symlink your dotfiles to the home directory (cd; ln -s ~/dotfiles/.zshrc
).
But that means you'll need to regularly git pull
changes (even with something like chezmoi you'll need to chezmoi update
). Say you have a dozen machines... doing an update on one machine means doing git pull
on 11 other machines. It's easy enough to hack around it (cron, rsync, etc), but I think I've got a better solution:
Put this somewhere in your .(ba/z)shrc
:
(git -C ~/dotfiles pull &> /dev/null &) > /dev/null 2>&1
This command will do a non-blocking-best-effort-stdout-supressed pull of your dotfiles repo every time you open a terminal. Since this command lives in a dotfile, it will be executed without any additional software, and you will never have to worry about git pull
(or cron or rsync) again. Set it and forget it.
Since
git pull
is being executed in the bg while loading the shell, the initial terminal session after a dotfile change may not have the most recent changes, and you may need to reload the config, e.g.. ~/.zshrc
(or just exit and re-open a terminal). I think that's a small price to pay for carefree synchronization.