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.xsessionis 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…
whatever
9 minutes later
Whoops - hit the button too quick there.
Why don’t you just make a symbolic link - ln -s $HOME/.config $HOME/Settings
11 minutes later
Frank: that’s what I currently am doing. However, I ought to be able to set it correctly rather than working around the problem :)
21 minutes later
There ~/.xprofile, which is read by gdm.
30 minutes later
/etc/profile is the usual UNIX way to do this kind of thing - think it works on Linux too. It usually contains system wide defaults and (I think) should work regardless of whether you use X or ssh, as long as you’re not using some weird shell that ignores it. Worth a try anyhow.
36 minutes later
Frank: /etc/profile will set it for all users on the system, not just me; same problem as /etc/xdg.
pclouds: I didn’t know about that, but it has the same problem as .xsession; it won’t work if I ssh in (or possibly if I switch to a different login manager).
52 minutes later
Well you could put some logic in there, e.g. within /etc/profile test for the existence of a file such as $HOME/.xdg_profile and include it if it exists.
Or test if $HOME/Settings exists and set the variable if it does.
Otherwise you’re possibly stuck with doing it in two places, once for ssh and once for X.
Still think a symlink is the easiest way though :-)
75 minutes later
Put it in
.config/FreeDesktop, of course! ;)3 hours later
Roberto: you’re all comedy all the time, you are :-)
3 hours later
I think .bashrc is loaded whenever bash is started.. And the gdm startup is a bash script (or maybe you use a crappy distro that uses another shell for gdm? Maybe this shell has an equivalent file?) On a unix system, I’ll bet there’s a shell somewhere in starting mostly anything.
5 hours later
5 hours later
You will find that ~/.profile is parsed when you login both via gdm (with almost all sessions managers too) and when you ssh in.
Go ahead and try it:
echo ”.profile was called” >> $HOME/bash-startup
7 hours later
I can confirm that ~/.profile is called when you log in - I use it to load the colour profile for my monitor, and so just after I log in first the screen does a noticeable colour shift.
22 hours later
Michael Maclean: aha. Yes. It does get run. *After* your autostart applications are autostarted. Useful, I don’t think. :)
24 hours later
Well it doesn’t sound like there is any single clean way of accomplishing it at the mo then.
You can get anything run before starting your session using ~/.dmrc ~/.xsession and ~/.profile.
in ~/.dmrc
[Desktop]
Session=default
in ~/.xsession (assuming your still using gnome)
export XDG_CONFIG_HOME=$HOME/Settings
gnome-session
in ~/.profile add your XDG_CONFIG_HOME line to the end (or beginning) too. .profile wont be read till after things have autostarted, but that dont matter as the var is already exported in ~/.xsession. It is only there for when you open terminals/bash/dash.
29 hours later
Oh, I didn’t realise it was after the autostart apps. But then, I don’t have any :)
38 hours later
CDE sources your profile at login if you set DTSOURCEPROFILE=true in ~/.dtprofile. It sounds like this is the behaviour you’re after.
You could get this by creating a .xsession that starts
#!/bin/bash –login
7 days later
Did you ever find a solution to this elsewhere? I’m quite interested in this as well.
4 weeks later