SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-09-09 14:28:58

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

XDG environment variables

XDG Environment variables
Goal:
    To provide a unified way to refer to some user directories, such as downloads, movies, video, etc
    see http://www.freedesktop.org/wiki/Software/xdg-user-dirs for a complete explanation
config files:
     /etc/xdg/user-dirs.conf
    /etc/xdg/user-dirs.defaults
program:
    xdg-user-dirs-update
set things up:
        the config files come with the package.
    edit user-dirs.conf when you prefer other directories
    to start with a clean slate:
        rm $HOME/.config/user-dirs.dirs $HOME/.config/usr-dirs.locale
    as yourself, run
        xdg-user-dirs-update
    this will create files $HOME/.config/user-dirs.dirs
                          $HOME/.config/usr-dirs.locale
    to make XDG-* environment variables available put this in /etc/profile, $HOME/.profile, /etc/bashrc or $HOME/.bashrc,
    depending on the environment in which you want the XDG* variables available. I used $HOME/.profile

        if [ -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs ]; then
            . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
            export XDG_DESKTOP_DIR XDG_DOWNLOAD_DIR XDG_TEMPLATES_DIR XDG_PUBLICSHARE_DIR XDG_DOCUMENTS_DIR XDG_MUSIC_DIR XDG_PICTURES_DIR XDG_VIDEOS_DIR
        fi

    reboot, restart gdm or re-login to activate the changes
    You can now use environment variables to refer to your user directories:
        ${XDG_DESKTOP_DIR}
        ${XDG_DOWNLOAD_DIR}

example:
    you want your downloads in $HOME/accepted:
        1. sudo edit /etc/xdg/user-dirs.conf
        2. rm $HOME/.config/user-dirs.dirs $HOME/.config/usr-dirs.locale
        3. as you, run:
               xdg-user-dirs-update
        4. in your shell scripts you can refer to your download dir as $XDG_DOWNLOAD_DIR

    if, after some time youwould like to change your download dir to $HOME/downloads:
        1. edit /etc/xdg/user-dirs.conf
        2. mkdir $HOME/downloads
        3. run xdg-user-dirs-update
    and thats it.
    You don't have to change your scripts, because $XDG_DOWNLOAD_DIR will now refer to $HOME/downloads

Hope this helps someone,
Enjoy #!

Offline

Help fund CrunchBang, donate to the project!

#2 2011-09-09 16:16:07

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: XDG environment variables

Thank you xaos52.
I wonder why this isn't already implemented by default?


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#3 2011-09-10 13:58:40

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: XDG environment variables

It usually is. That's a Debian special treatment malfunction of some sorts. Ignoring this is the reason why so many applications fire their stuff in ~/.[stuff] instead of ~/.config/[stuff], because a certain huge developer community... uh... I should validate this one before I start the rant :-D


I'm so meta, even this acronym

Offline

#4 2011-09-10 16:41:58

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: XDG environment variables

@xaos just one thought - why don't you just edit $HOME/.config/user-dirs.dirs instead of /etc/xdg/user-dirs.conf and running xdg-user-dirs-update? Why apply your changes to all the other users?

Also the file to change default directories would be  /etc/xdg/user-dirs.defaults according to that link.

@awebb XDG_CONFIG_HOME is the variable you're referring to? That isn't actually set in the xdg-user-dirs stuff...

Last edited by johnraff (2011-09-10 16:49:01)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#5 2011-09-10 16:49:54

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: XDG environment variables

@JohnRaff: Well I am the only user on my system. So, makes no difference smile
Plus: I am on 'testing' and using GDM, and I see that GDM should automatically apply any changes I make to /etc/xdg/user-dirs.conf every time it starts up.
This is Linux. You are free to manage it at the user level, if you prefer that.
hth

Edit: Well, I am not sure now, I would have to test, but I suspect that making changes at system level will be enforced at user level, I mean if the sysadmin changes the /etc config files, next time the user logs in, GDM will apply those changes to the user config files.

Last edited by xaos52 (2011-09-10 16:56:18)

Offline

#6 2011-09-10 18:43:32

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: XDG environment variables

OK, I ran some tests and here are the conclusions (for my setup, which is Debian 'test' repo with GDM3 and gnome-session):
1. Existing local config files are not overwritten by changes to system config files.
So, once the local config files exist, those are the ones that need to be managed.
--> If you want to change your local XDG_* env vars, edit $HOME/.config/user-dirs.conf
2. When the local config files do NOT exist, the system config files will be copied to the local config files the first time the user logs in via GDM. So system config files are DEFAULTS for non-existing local config files.
IMPORTANT NOTE:
When you create a new user, and you opt to copy the config files from /etc/skel, the local config files will be created from /etc/skel/.config
They may need to be edited to adjust to the users preferences.
When you dont copy from /etc/skel, the user config files will be created from the system config files the first time the new users log in via GDM.
Hope this clears things up.

Last edited by xaos52 (2011-09-10 18:44:28)

Offline

#7 2011-09-13 04:53:54

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: XDG environment variables

^ $HOME/.config/user-dirs.conf does not exist on my (#! squeeze) system. I have user-dirs.locale and user-dirs.dirs, which sets user directories like Downloads, but not XDG_CONFIG_HOME or XDG_DATA_HOME.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#8 2011-09-13 05:01:12

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: XDG environment variables

^ Same here.
The .conf was my mistake.
I do not know why they did not add those two.
I suppose you can add them without any side effects.
JP

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo