DEV Community

David Mohl
David Mohl

Posted on • Originally published at david.coffee on

Syncing app configurations across machines with unisync

unisync

tl;dr : unisync is a little tool I wrote that diffs and syncs your application settings across Macs, powered by unison

Config management across machines is kind of a PITA. Some apps luckily natively support syncing settings, but most don’t.

There are some solutions like the excellent Mackup that try to fix this issue by moving all config files into a shared folder (like Dropbox), then creating symlinks from the application settings folders (eg ~/Library/Preferences/xxxx.plist) into that Dropbox folder.

I used mackup for a while (even with my own config files), but eventually got frustrated when symlinks randomly broke, for example, because the app decided it wanted to write the full file fresh to disk, effectively overwriting the symlink. Then some other apps detect symlinks and refuse to read them.

I tried to mitigate that by creating a PR to mackup that adds support for hardlinks, but tl;dr: hardlinks in APFS are not really hardlinks, and this is even more fragile with cloud storage than using symlinks.

Unison is great

unison is one of these really old tools that’s been around and developed forever. It’s a

*“Unison is a file-synchronization tool for POSIX-compliant systems (e.g. BSD and GNU/Linux), macOS and Windows, with the caveat that the platform must be supported by OCaml”

basically, it syncs files, kind of like a bi-directional rsync: Where rsync syncs one way (and alternatively deletes files), unison goes both ways and finds files that changed, got added or deleted across multiple directory nodes.

Bi-directional sync makes it great for those pesky config dirs that could change on one host without us noticing. By diffing the directories against, say, a directory in Dropbox, unison can determine what actually changes, and copies the files accordingly.

If a file is updated on Host B and is then synced through Dropbox to Host A, unison on Host A would see that the file in Dropbox is now newer than on the local one, and overwrite it with the version from Dropbox.

unison can even sync across machines directly!

Mackup + Unison = Unisync

That brings us to unisync. Unisync is using the Mackup idea of having a library of app configurations that state where config files are, but instead of using symlinks, it calls into unison to do the actual copying of files. So in theory, if files changed on one machine and then get synced to other machines, those files would get marked as changed / new, and get copied over the existing local file.

Unisync screenshot

Because unisync is using unison under the hood, we can do more fancy things like providing a tree with files we want to handle, but add regex or naming patterns to ignore rules:

name: Raycast
friendlyName: raycast
files:
  - basePath: ~/Library/Preferences/
    includedFiles:
      - com.raycast.macos.plist
    ignoredFiles:
      - Name somethingToIgnore.plist

Enter fullscreen mode Exit fullscreen mode

Unisync also supports the entire Mackup app library for syncing to get you started, and comes with LaunchAgents that make it run automatically in the background.

Check it out on GitHub and let me know if this tool is useful for you: https://github.com/dvcrn/unisync

Top comments (0)