How to properly symlink files in the ~/Library/Preferences

Solution 1:

How can I reliably symlink files in the ~/Library/Preferences

Don't.

These files are generally not for user consumption. They are the support files for the applications you use every day. Some are nothing more than configuration files while others store data like (Firefox) recently visited sites, bookmarks, etc.

I want to version these files in my dotfiles repo.

Why? Unless you're a dev, there's no reason to version these files especially since some change not just daily, but as you use the app.

This also allows me to rename the file to something convenient, even if the original developer picked a bad name for the config file.

Again, this isn't meant for general consumption and second guessing the developer and their naming conventions can cause issues. For instance, many applications upgrade by simply downloading only the changed files while others download the whole application and simply overwrite what was there (Firefox is a good example). Either way, it's expecting it's support files to be where the dev said they would be. There are also many cases in which the config file must be migrated as it uses a different format and the "tools" which the dev implements to do this migration may not be expecting a symlink.

However this doesn't appear to work consistently on Macs - sometimes the symlink itself gets overwritten, sometimes setting the symlink to "Locked" fixes that and sometimes no.

Case in point.

I like my dotfiles repo to be in its own tidy folder

Ok...I can definately apprecieate a neat and orderly file hieracharcy. However, since the applications will be expecting the Library files to be where they are originally, that folder will just be the same unorganized, badly named list of symlinks instead. So, basically, all for naught.