practicalli / blog-cryogen

Cryogen powered blog with all the content used to generate the static website.
https://practical.li/blog-cryogen/
3 stars 2 forks source link

Aricle: Adopting FreeDesktop.org XDG standard for configuration files #141

Closed practicalli-johnny closed 2 years ago

practicalli-johnny commented 2 years ago

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.

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.

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.

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

git config --global core.excludesFile ignore-global

Neovim XDG/nvim

Clojure XDG/clojure ~/.clojure

Clojure LSP XDG/clojure-lsp | ~/.clojure-lsp or .lsp (deprecated)

practicalli-johnny commented 2 years ago

Published at https://practical.li/blog/posts/adopt-FreeDesktop.org-XDG-standard-for-configuration-files/