Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: do not use ~/Library/Preferences #53

Closed
divVerent opened this issue Apr 10, 2023 · 5 comments
Closed

macOS: do not use ~/Library/Preferences #53

divVerent opened this issue Apr 10, 2023 · 5 comments

Comments

@divVerent
Copy link

~/Library/Preferences is reserved for .plist files - one should never create application-specific subdirectories in there, but each application is supposed to just have ONE .plist file in there, named using its bundle ID.

This differs from XDG_CONFIG_HOME as that one expects per-app directories.

See also:

Instead, XDG_CONFIG_HOME should be ~/Library/Application Support, too.

@adrg
Copy link
Owner

adrg commented Apr 10, 2023

Hi @divVerent

I'm not sure I understand the issue. XDG_CONFIG_HOME does default to ~/Library/Application Support if the environment variable is not set or empty.

@divVerent
Copy link
Author

I think I see where I am wrong. The wrong directory ~/Library/Preferences is in XDG_CONFIG_DIRS https://github.com/adrg/xdg/blob/master/paths_darwin.go#L30, but not in XDG_CONFIG_HOME https://github.com/adrg/xdg/blob/master/paths_darwin.go#L28.

So that's still wrong, but basically has zero impact as XDG_CONFIG_DIRS is only for reading, not writing.

Feel free to close, although it'd be nice to have a code comment explaining why the plist directories are in there.

@adrg
Copy link
Owner

adrg commented Apr 12, 2023

So that's still wrong, but basically has zero impact as XDG_CONFIG_DIRS is only for reading, not writing.

As the Apple developer guide states, files in the ~/Library/Preferences directory should only be read or written using their provided API. However, I don't see anything wrong in having one more location to search files. Although unlikely, if some config file happens to be in that directory, the library simply provides its location. It has nothing to do with reading or writing that file.

@adrg adrg closed this as completed Apr 12, 2023
@BlakeWilliams
Copy link

@adrg I understand this has already been closed, but I ran across this because I was wondering why lazygit wasn't able to find my config in ~/.config/lazygit/config.yml which sent me down a bit of a rabbit hole. There's an entire thread about it since ~/Library/Application\ Support/ is not where developers expect to define or set configuration for CLI apps.

I was looking at contributing to LazyGit to add support for ~/.config as the first directory to look at before falling back to the current default (~/Library/Application\ Support/). I thought ideally that could be implemented upstream in this package if there's interest in getting the behavior more in line with other CLI applications. That way any package utilizing this package can take advantage of that behavior.

I'd be be happy to look at implementing that here if there's interest (and if I find the time!)

@adrg
Copy link
Owner

adrg commented Oct 14, 2024

@BlakeWilliams I think adding ~/.config as an extra location to look for config files on macOS is a good idea. I could add ~/.config at the end of the list of default config directories (i.e. the default locations for XDG_CONFIG_DIRS). That should not produce any breaking changes and xdg.SearchConfigFile would find config files at that location (assuming XDG_CONFIG_DIRS is not defined, but it should not be on macOS usually).

I think I'll make this change and include it in the next release, which is this week as I already had one planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants