What are the step to move all your dotfiles into XDG directories?

Indeed, the current short answer to the question is you can't, as some application hardcode the path. Nevertheless, many application which doesn't specifically support XDG directories enable to set other directories through environment variables. Some time you need to be able to change the system wide configuration, for example with shell, but most of the time, you should be able perform the step as a unprivileged user.

Setting you shell

# Setting bash to use $XDG_CONFIG_HOME/bash, defaults to ~/.config/bash
confdir=${XDG_CONFIG_HOME:-$HOME/.config}/bash

### Moving existing files
mkdir -p -- "$confdir"
for file in "$HOME"/.bash*; do
    dest=$confdir/$(basename "${file:1}") 
    mv -i -- "$file" "$dest" # don't overwrite without permission
done

### Sourcing and setting variables
sudo sh -c 'cat >>/etc/profile.d/bash_in_xdg_config_home.sh <<CONF
# Make bash follow the XDG_CONFIG_HOME convention
_confdir=\${XDG_CONFIG_HOME:-\$HOME/.config}/bash
if [ -d "$_confdir" ] &&  [ "\$0" = "bash" ]
then
    . "\$_confdir"/bash_profile
    . "\$_confdir"/bashrc
    HISTFILE=\$_confdir/bash_history
fi
unset _confdir
CONF
'

sudo sh -c 'cat >>/etc/bash.bash_logout <<CONF
if [ -s "\${XDG_CONFIG_HOME:-\$HOME/.config}/bash/bash_logout" ]
then
    . "\${XDG_CONFIG_HOME:-\$HOME/.config}/bash/bash_logout"
fi
CONF
'

# Setting zsh
## System wide configuration (using xdg directories)
sudo sh -c 'cat >>/etc/zshenv <<CONF
if [[ -d "\${XDG_CONFIG_HOME:-\$HOME/.config}"/zsh ]]
then
        export ZDOTDIR=\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh
fi
CONF
'

If you use several shell, for example zsh for interactive shell, but an other for scripting, you may want to $XDG_CONFIG_HOME/profile file, that you will source in relevant shell initialization script.

Setting environment variables

# bazaar
export BZRPATH=$XDG_CONFIG_HOME/bazaar
export BZR_PLUGIN_PATH=$XDG_DATA_HOME/bazaar
export BZR_HOME=$XDG_CACHE_HOME/bazaar

# gnupg
export GNUPGHOME=${XDG_CONFIG_HOME}/gnupg

# ICEauthority
export ICEAUTHORITY=${XDG_CACHE_HOME}/ICEauthority

#  less
export LESSHISTFILE="${XDG_CONFIG_HOME}/less/history"
export LESSKEY="${XDG_CONFIG_HOME}/less/keys"



# mplayer
export MPLAYER_HOME=$XDG_CONFIG_HOME/mplayer

# subversion
export SUBVERSION_HOME=$XDG_CONFIG_HOME/subversion


# vim
export VIMINIT='let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $MYVIMRC'
export VIMDOTDIR="$XDG_CONFIG_HOME/vim"

Work around

SSH

SSH does provide a way to change the client configuration file, but – as far as I found – only through command line. So one solution to always invoke the clients with a none default emplacement may be :

if [ -s "${XDG_CONFIG_HOME}/ssh/config" ]
then
    SSH_CONFIG="-F ${XDG_CONFIG_HOME}/ssh/config"
fi
if [ -s "${XDG_CONFIG_HOME}/ssh/id_dsa" ]
then
    SSH_ID="-i ${XDG_CONFIG_HOME}/ssh/id_dsa"
fi

alias ssh="ssh $SSH_CONFIG $SSH_ID "
alias ssh-copy-id="ssh-copy-id $SSH_ID"

And your ${XDG_CONFIG_HOME}/ssh/config should contain something like :

Host *
    IdentityFile /home/user/.config/ssh/id_dsa
    UserKnownHostsFile /home/user/.config/ssh/known_hosts

What doesn't work yet

Although GNUPGHOME is a documented variable, under Fedora 21 you'll end up with the creation of a new ~/.gnupg directory when you launch a new session.

Although ICEauthority is a documented variable, under Fedora 21 you'll end up with the creation of a new cookie when you launch a new session.

The dotfile ~/.swt content should probably be stored directly into ${XDG_DATA_HOME}, as both have lib directories. No documentation was found on how to to that if it's possible.

Mozilla products doesn't support an appropriate environment variable, see Mozilla products doesn't allow to use a custom user configuration directory and Support for the Freedesktop.org XDG Base Directory Specification.

Other useful sources

  • Move your config files to $XDG_CONFIG_HOME
  • https://github.com/woegjiub/.config/blob/master/bash/xdg.sh
  • http://www.reddit.com/r/linux/comments/2v8rv2/move_your_config_files_to_xdg_config_home/ (Move your config files to $XDG_CONFIG_HOME)
  • https://github.com/grawity/dotfiles/blob/master/.dotfiles.notes

I recommend consulting the Arch Linux wiki page XDG Base Directory support which is continuously updated.

GIT

I just moved my .gitconfig to XDG_CONFIG_HOME on OSX. Per the git-config documentation (link omitted due to reputation).

Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or
empty, $HOME/.config/git/config will be used. Any single-valued variable 
set in this file will be overwritten by whatever is in ~/.gitconfig. It is
a good idea not to create this file if you sometimes use older versions of
Git, as support for this file was added fairly recently.

I set the environment variable using the instructions in Setting the system-wide PATH environment variable in Mavericks. Note that you will need to create the file XDG_CONFIG_HOME/git/config yourself and if ~/.gitconfig exists it will take precedence.

VIM

I used Tom Vincent's 2011 article Vim respect XDG and it seems to work. I'm not sure about the above answer; VIMDOTDIR doesn't seem to be a thing.