Configuration files are usually written to the root of the $HOME directory, making it more challenging to put them under version control.
Setting the XDG_CONFIG_HOME environment variable places configuration files under a single directory, as well as moving data and cache files to their own locations. It also minimises the dot files and directories
Operating systems rarely set a value for XDG_CONFIG_HOME, although its simple to setup and migrate existing configuration files.
XDG_RUNTIME_DIR runtime files bound to the login status of the user
XDG_CONFIG_DIRS and XDG_DATA_DIRS can be used to preference ordered set of directories to search for their respective files, rather than just a single directory.
The environment variables must be set to an absolute path to be consider a valid path. XDG variables can be defined with other environment variables, e.g. HOME, as long as the path resolves as absolute.
The XDG basedir specification has not yet become the default in many Unix distributions, although the vast majority of tools and applications support configurations that follow the basedir specification.
Defining XDG_CONFIG_HOME before installing any tools or applications is the simplest approach.
If applications already have configuration that should be kept, then they are easily migrated to the new location and typically default to the HOME directory if not found in the respective XDG_CONFIG_HOME/ directory
Setting environment variables
XDG_CONFIG_HOME should be defined for applications run
Take linux as an example (should be the same for Mac with same shell)
Zsh - prezto
Install prezto in XDG_CONFIG_HOME/zsh directory
TIP: rather than link the prezto dot files
prezto requires ~/.zshenv to bootstrap the location of prezto configutation.
Set the XDG_CONFIG_HOME location, typically set to HOME/.config
Recommend using a symbolic link to the actual XDG_CONFIG_HOME/zsh/zshenv file
Emacs
emacs | .emacs.d
Spacemacs
Set SPACEMACSDIR to XDG_CONFIG_HOME/spacemacs
Git
config (aka .gitconfig)
templates/
ignore-global (aka .gitignore-global) - add to config file using relative location (keep them both in the same XDG_CONFIG_HOME/git directory)
Configuration files are usually written to the root of the
$HOME
directory, making it more challenging to put them under version control.Setting the
XDG_CONFIG_HOME
environment variable places configuration files under a single directory, as well as moving data and cache files to their own locations. It also minimises the dot files and directoriesOperating systems rarely set a value for
XDG_CONFIG_HOME
, although its simple to setup and migrate existing configuration files.FreeDesktop.org produces standards under the Cross-Desktop Group, referred to as XDG.
Two of the most relevant specifications for users are:
This article will focus on the basedir configuration and document the XDG locations for a range of common developer tools
Standard Environment variables
The XDG Base Directory Specification separates configuration, data, runtime and cache files in separate locations, e.g.
.config
,.cache
, etc..Each location organises application specific files within a directory of the same name as that application.
XDG_CONFIG_HOME
user-specific configuration files, default$HOME/.config
XDG_DATA_HOME
user-specific data files. default$HOME/.local/share
XDG_STATE_HOME
user-specific state data$HOME/.local/state
XDG_CACHE_HOME
user-specific non-essential (cached) data, default$HOME/.cache
XDG_RUNTIME_DIR
runtime files bound to the login status of the userXDG_CONFIG_DIRS
andXDG_DATA_DIRS
can be used to preference ordered set of directories to search for their respective files, rather than just a single directory.A detailed description is covered in the freedesktop.org basedir specification.
Configuring Linux / Unix system
The XDG basedir specification has not yet become the default in many Unix distributions, although the vast majority of tools and applications support configurations that follow the basedir specification.
Defining XDG_CONFIG_HOME before installing any tools or applications is the simplest approach.
If applications already have configuration that should be kept, then they are easily migrated to the new location and typically default to the HOME directory if not found in the respective
XDG_CONFIG_HOME/
directorySetting environment variables
XDG_CONFIG_HOME
should be defined for applications runTake linux as an example (should be the same for Mac with same shell)
Zsh - prezto
Install prezto in
XDG_CONFIG_HOME/zsh
directoryprezto requires
~/.zshenv
to bootstrap the location of prezto configutation.Set the XDG_CONFIG_HOME location, typically set to HOME/.config
Recommend using a symbolic link to the actual
XDG_CONFIG_HOME/zsh/zshenv
fileEmacs
emacs | .emacs.d
Spacemacs
Set
SPACEMACSDIR
toXDG_CONFIG_HOME/spacemacs
Git
config (aka .gitconfig) templates/ ignore-global (aka .gitignore-global) - add to config file using relative location (keep them both in the same XDG_CONFIG_HOME/git directory)
Neovim XDG/nvim
Clojure XDG/clojure ~/.clojure
Clojure LSP XDG/clojure-lsp | ~/.clojure-lsp or .lsp (deprecated)