Setting an environment variable for all your apps

In the New World Order, Linux apps should all store their user-specific data according to the FreeDesktop Base Directory specification, which in practice means that config details for myapp end up in $HOME/.config/myapp. All well and good. However, I don’t like having configuration stored in dotfiles; I like to be able to get at it more easily, so I want it in $HOME/Settings. The XDG spec provides for this: you set an environment variable XDG_CONFIG_HOME (which defaults to $HOME/.config) and then everything uses it. Great! But…where do I set this variable so that all the apps get it? Some suggestions:

  • $HOME/.bashrc, $HOME/.bash_profile, $HOME/.profile — as far as I can tell, these aren’t run as part of the login process, so they’re no good. They get run when you start bash, which means when you first fire up a terminal.
  • $HOME/.gnomerc — gets run by gdm. Might be a Debianism, and doesn’t work if I change away from gdm a few months from now
  • $HOME/.xinitrc, $HOME/.xsession — get run if you’re in X but not if you’re running over SSH, and .xsession is a Debianism
  • /etc/xdg/user-dirs.conf — this will change it for all users on the machine, not just me
  • Something in PAM. Perhaps. It’s not clear what, though.
  • A file of my choice, which I then source from all of the above places. This is doable but seems stupid to me, and I’m bound to miss something.
  • Something else. This is where you come in; where am I meant to set the environment so that everything gets access to it?

Answers on a postcard…

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)