From 12843a0c67f5965f8086958858f88259ef85c139 Mon Sep 17 00:00:00 2001 From: sev Date: Fri, 5 Apr 2024 14:47:34 -0500 Subject: [PATCH] zshenv: update and simplify XDG --- etc/zsh/.zshenv | 58 +++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/etc/zsh/.zshenv b/etc/zsh/.zshenv index f1e6a55..2cbb88a 100644 --- a/etc/zsh/.zshenv +++ b/etc/zsh/.zshenv @@ -216,52 +216,43 @@ if [[ ! -v _sev_setup_xdg ]] { emulate sh -c "source $XDG_CONFIG_HOME/user-dirs.dirs" typeset -UT XDG_DATA_DIRS xdg_data_dirs - if [[ -v XDG_DATA_HOME ]] { - export XDG_DATA_HOME - } elif [[ ! -e ~/.local/share ]] { - mkdir -m760 ~/.local/share - } - xdg_data_dirs=($XDG_DATA_HOME /{opt,usr/local,usr/pkg,usr}/share - ${XDG_DATA_DIRS:+${xdg_data_dirs%%/}}) + [[ -v XDG_DATA_HOME ]] && export XDG_DATA_HOME + [[ -e ${XDG_DATA_HOME:-~/.local/share} ]] || + mkdir -m760 ${XDG_DATA_HOME:-~/.local/share} + xdg_data_dirs=($XDG_DATA_HOME ${XDG_DATA_DIRS:+${xdg_data_dirs%%/}} + /{usr{,/local,/pkg},opt{,/*{/*,}}}/share(N)) + xdg_data_dirs=($xdg_data_dirs(/N)) export XDG_DATA_DIRS typeset -UT XDG_CONFIG_DIRS xdg_config_dirs - if [[ -v XDG_CONFIG_HOME ]] { - export XDG_CONFIG_HOME - } elif [[ ! -e ~/.config ]] { - mkdir -m760 ~/.config - } + [[ -v XDG_CONFIG_HOME ]] && export XDG_CONFIG_HOME + [[ -e ${XDG_CONFIG_HOME:-~/.config} ]] || + mkdir -m760 ${XDG_CONFIG_HOME:-~/.config} # I am of the belief .local should follow FHS /usr/local... - [[ -e ~/.local/etc ]] || ln -s ~/.config ~/.local/etc - xdg_config_dirs=($XDG_CONFIG_HOME - ${XDG_CONFIG_DIRS:+${xdg_config_dirs%%/}} - {/opt,/usr/local,/usr/pkg,}/etc/xdg) + [[ -e ~/.local/etc ]] || ln -s ${XDG_CONFIG_HOME:-~/.config} ~/.local/etc + xdg_config_dirs=($XDG_CONFIG_HOME ${XDG_CONFIG_DIRS:+${xdg_config_dirs%%/}} + {,/usr{,/local,/pkg},opt{,/*{/*,}}}/etc/xdg(N)) + xdg_config_dirs=($xdg_config_dirs(/N)) export XDG_CONFIG_DIRS - if [[ -v XDG_STATE_HOME ]] { - export XDG_STATE_HOME - } elif [[ ! -e ~/.local/state ]] { - mkdir -m760 ~/.local/state - } + [[ -v XDG_STATE_HOME ]] && export XDG_STATE_HOME + [[ -e ${XDG_STATE_HOME:-~/.local/state} ]] || + mkdir -m760 ${XDG_STATE_HOME:-~/.local/state} if [[ -v XDG_CACHE_HOME ]] { export XDG_CACHE_HOME } else { - if [[ -v _sev_tmp ]] { - export XDG_CACHE_HOME=$_sev_tmp/.xdg.cache - [[ -e $XDG_CACHE_HOME ]] || mkdir -m700 $XDG_CACHE_HOME - } elif [[ ! -e ~/.cache ]] { - mkdir -m700 ~/.cache - } + export XDG_CACHE_HOME=$_sev_tmp/.xdg.cache } + [[ -e ${XDG_CACHE_HOME:-~/.cache} ]] || + mkdir -m700 ${XDG_CACHE_HOME:-~/.cache} + # NOTE: this can be set by systemd or other pre-shell supervisor, and if + # any services were started such as pipewire, we need to use the + # existing runtime dir to preserve runtime state if [[ -v XDG_RUNTIME_DIR ]] { - # NOTE: this can be set by systemd or other pre-shell supervisor, and - # if any services were started such as pipewire, we need to use - # the existing runtime dir so that we can get any existing - # program sockets or other data export XDG_RUNTIME_DIR - } elif [[ -v TMPDIR ]] { + } else { # make runtime dir in our session-specific tmpdir export XDG_RUNTIME_DIR=$TMPDIR/.xdg.runtime # same as in tmpdir creation, ensure dir doesn't exist @@ -270,8 +261,9 @@ if [[ ! -v _sev_setup_xdg ]] { } elif [[ -e $XDG_RUNTIME_DIR ]] { rm -rf $XDG_RUNTIME_DIR 2>/dev/null } - mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null } + [[ ! -e $XDG_RUNTIME_DIR ]] && + mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null export _sev_setup_xdg= } -- 2.47.0