[zsh] A new env init function to set XDG path variables
This commit is contained in:
parent
4f06d80da6
commit
91da2fc583
2 changed files with 35 additions and 0 deletions
34
zsh/func/init-env-default-xdg-vars
Normal file
34
zsh/func/init-env-default-xdg-vars
Normal 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 "$@"
|
||||
1
zshenv
1
zshenv
|
|
@ -46,6 +46,7 @@ autoload -Uz do_init_functions
|
|||
|
||||
typeset -a zsh_init_env_functions=( \
|
||||
init-env \
|
||||
init-env-default-xdg-vars \
|
||||
init-env-path \
|
||||
init-env-tilde-paths \
|
||||
init-env-python \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue