Live data from Hacker News

Use the XDG Base Directory Specification

xdgbasedirectoryspecification.com

41–50 of 214 posts

Re: Use the XDG Base Directory Specification

#41
post #27

The second example is a nice start, but I'd really like to see invisible files/folders in ~/ done away with altogether. So starting with that example, I might add a visible ~/Library/ folder, then move ~/.config/ and ~/.local/ in there as ~/Library/Config/ and ~/Library/Local/ as normal visible folders. Same for .bashrc, .profile, etc; put them in ~/Library/Config/ without the dots.

Yeah, it's a bit alien on macOS. There is no good mapping for some of these folders. For example, on macOS application configuration isn't even supposed to be done directly via application-specific files . macOS has its User Defaults subsystem, with `defaults read`/`defaults write` commands. And of course this isn't usable by typical command-line tools that don't have a Bundle ID.

The system that you mentioned is specifically for macOS Desktop apps. I think even Apple is drawing a line there. I don‘t know of any Apple commandline tool which has a configuration in plist format etc. But I might be wrong.

Re: Use the XDG Base Directory Specification

#42
Oh I‘m fighting the battle for a clean home directory for years. I even use a setup on macOS to set specific environment variables via systemd during login so I can link them into the .config directory.

Only issue with my setup in general is that I can‘t just replicate it for other people. I moved .aws directory in .config/aws and I sometimes forget what the default for most tools is or where I helped the tool out to „find the right path“.

I also make sure when writing scripts/cli tools to use the XDG spec. In rust I use the dirs crate for example. I even go so far to never hardcode it for my own config scripts/files just in case I think about going from ~/.config to ~/.my_configurations or whatever.

Re: Use the XDG Base Directory Specification

#45
I completely agree with the article that more people should use the spec. I already do this for all my personal projects and nothing drives me up the wall more than seeing random config files strewn about.

It also provides an easy target for freeing disk space if you do run into issues (just `rm -r $XDG_CACHE_HOME`).

That said, I do think the spec would be improved by defining what constitutes a "user-specific data file" and how that is different from a "user-specific state file". Wouldn't "user-specific data files" just be "files" from a users perspective? I like the idea they have for this, but it's kind of under defined.

Though that's probably a good thing because no one wants a ontological tome to wade through when working on a bash script or the like.

Re: Use the XDG Base Directory Specification

#47
post #16

If you are using Rust, you can easily conform to this by using `directories` crate: https://docs.rs/directories/latest/directories/struct.BaseDi...

I am not going to look it up for every language, but you can safely assume all major languages have a similar library to make this easy.

Re: Use the XDG Base Directory Specification

#48

The second example is a nice start, but I'd really like to see invisible files/folders in ~/ done away with altogether. So starting with that example, I might add a visible ~/Library/ folder, then move ~/.config/ and ~/.local/ in there as ~/Library/Config/ and ~/Library/Local/ as normal visible folders. Same for .bashrc, .profile, etc; put them in ~/Library/Config/ without the dots.

If everything honored this spec, including the part where it reads environment variables to see where the different directories are, you could do that by sticking the right variables in your environment. I think the one legitimate exception to the rule is profile, because you need that in order to set the variables in the first place. So that one would somehow have to be hard coded to at least have a wider search pat…

You could set the variables in a pam module, then you don’t need to worry about profile

Re: Use the XDG Base Directory Specification

#49

I strongly disagree: the dot files cause very little inconvenience because they’re typically hidden and they’re easier to type and list than the XDG spec stuff

It’s much easier to back up/certain config files when they are all in one place.

Re: Use the XDG Base Directory Specification

#50
How did OP manage to get rid of ~/.mozilla? It's the only offending dotfile left in my $HOME and the stickiest. Until Mozilla fixes their 19-year-old feature request to support XDG [1], I couldn't find a workaround that wasn't a total hack.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=259356

Post reply on HN