Topic: 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 #!