[zsh] A new env init function to set XDG path variables

This commit is contained in:
Eryn Wells 2026-01-18 08:40:01 -07:00
parent 4f06d80da6
commit 91da2fc583
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,34 @@
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
# See https://specifications.freedesktop.org/basedir/latest/ for definitions of
# these paths.
function init-env-default-xdg-vars
{
zmodload zsh/zutil
local -a opt_create
zparseopts -a opt_args -D -E -F - \
{c,-create,-no-create}=opt_create
export \
XDG_BIN_HOME=${XDG_BIN_HOME:-$HOME/.local/bin} \
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache} \
XDG_CONFIG_HOME=${XDG_CACHE_HOME:-$HOME/.config} \
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} \
XDG_STATE_HOME=${XDG_DATA_HOME:-$HOME/.local/state}
if [[ $opt_create[(I)--no-create] -ne 0 ]]; then
mkdir -p -m 0700 \
$XDG_BIN_HOME \
$XDG_CACHE_HOME \
$XDG_CONFIG_HOME \
$XDG_DATA_HOME \
$XDG_STATE_HOME
fi
}
init-env-default-xdg-vars "$@"