This is as days pass by, by Stuart Langridge

And this is Setting an environment variable for all your apps, written , and concerning LazyWeb, Linux

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...

Comments

Frank O'De

whatever

Frank O'Dwyer

Whoops - hit the button too quick there.

Why don't you just make a symbolic link - ln -s $HOME/.config $HOME/Settings

sil

Frank: that's what I currently am doing. However, I ought to be able to set it correctly rather than working around the problem :)

pclouds

There ~/.xprofile, which is read by gdm.

Frank O'Dwyer

/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.

sil

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).

Frank O'Dwyer

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 :-)

Roberto

Put it in .config/FreeDesktop, of course! ;)

sil

Roberto: you're all comedy all the time, you are :-)

Tester

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.

sil

Tester: .bashrc isn't sourced as part of startup. I know this because I wrote

echo "I was called" >> $HOME/bash-startup

in .bashrc and reboted the machine; no bash-startup file was created.

karl

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

Michael Maclean

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.

sil

Michael Maclean: aha. Yes. It does get run. *After* your autostart applications are autostarted. Useful, I don't think. :)

karl

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.

Michael Maclean

Oh, I didn't realise it was after the autostart apps. But then, I don't have any :)

Peter Oliver

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

Dennis Fisher

Did you ever find a solution to this elsewhere? I'm quite interested in this as well.

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.