Skip to content

xdg

XDG Base Directory Specification helpers.

Returns fs.Path values for standard user directories, respecting environment variable overrides per the XDG spec.

Functions

data_home()

Returns the XDG user data directory ($XDG_DATA_HOME).

Falls back to ~/.local/share if the variable is absent or empty.

config_home()

Returns the XDG user configuration directory ($XDG_CONFIG_HOME).

Falls back to ~/.config if the variable is absent or empty.

state_home()

Returns the XDG user state directory ($XDG_STATE_HOME).

Falls back to ~/.local/state if the variable is absent or empty.

cache_home()

Returns the XDG user cache directory ($XDG_CACHE_HOME).

Falls back to ~/.cache if the variable is absent or empty.

runtime_dir()

Returns the XDG runtime directory ($XDG_RUNTIME_DIR), or nil if unset.

Intended for user-specific non-persistent runtime files such as sockets and named pipes. This directory may not exist on all systems.

data_dirs()

Returns the system-wide XDG data search directories ($XDG_DATA_DIRS).

Falls back to [/usr/local/share, /usr/share] if the variable is absent or empty. Only absolute paths are included.

config_dirs()

Returns the system-wide XDG configuration search directories ($XDG_CONFIG_DIRS).

Falls back to [/etc/xdg] if the variable is absent or empty. Only absolute paths are included.