Where your program's configuration files ('dotfiles') should go today

June 14, 2023

Over on the Fediverse, Ben Zanin had a question:

Is there a general consensus about the preference order of dotfiles and config directories?

Let's say we have a tool that reads an optional config file & populates/uses a small state file.

1. There is the traditional ~/.example/ dir that would contain `config` and `db`
2. There is the XDG ~/.config/example/config and ~/.local/example/db
3. There is the truly ancient ~/.examplerc / ~/.example.db convention

What is your preferred ordering of these options when checking all, most to least?
[poll elided]

Of course I chimed in with my views:

I voted 2, 1, 3, but really you should only support 2 1 and 3 as a backward compatibility measure if you ever originally supported them. If you're starting from scratch these days with a new program, IMHO you should only support the XDG approach. $HOME/.config is just less clutter.

In my view this isn't about adhering to the XDG standard, it's about getting things out of $HOME. Unix dotfiles were always a (somewhat accidental) hack, and over the years we've accumulated entirely too many of them in our $HOMEs. The XDG option isn't particularly perfect, but it's at least a standard approach and it achieves the goal of getting dotfiles out of $HOME. As a side effect the XDG approach makes things more legible if you look in ~/.config.

(You should look for an explicitly set $XDG_CONFIG_HOME, though, rather than hard-coding $HOME/.config. It's not that much extra work; in shell scripts it's almost free.)

You can raise assorted objections to the XDG standard, but it has two benefits. First, it's better than what we had before, when everyone put things in $HOME. Second, it's something (ie, a single place) that people have broadly agreed on, which matters because that's what keeps us from yet more clutter (cue the famous xkcd comic on standards). In this situation, one imperfect standard is better than a bunch of different groups making their own perfect standards, each of which would give us some new top level directories in your $HOME.

(The XDG Base Directory Specification definitely originated on Linux, but it's applicable to any Unix and I don't think it conflicts with what any of the other free Unixes are doing (or not doing) here. Plus, there's a growing number of programs that are going to use it because they have to pick somewhere to put their files, and the XDG way beats the alternative.)

Written on 14 June 2023.
« The Certificate Authority's view of Certificate Transparency and CT Logs
The evaporation of lots of .ga domains »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Jun 14 22:35:20 2023
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.