From 4ced48ed9172523adccbd9b8cc7c6d8448aaaf65 Mon Sep 17 00:00:00 2001 From: sev Date: Tue, 10 Oct 2023 10:16:10 -0500 Subject: [PATCH] zsh: add load-site-dotfile to replace site source --- base/.zshenv | 6 ++---- etc/zsh/.zlogin | 2 +- etc/zsh/.zlogout | 2 +- etc/zsh/.zprofile | 17 ++++++++++++----- etc/zsh/.zshrc | 2 +- etc/zsh/functions/Misc/load-site-dotfile | 10 ++++++++++ 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 etc/zsh/functions/Misc/load-site-dotfile diff --git a/base/.zshenv b/base/.zshenv index 45ea339..274fc10 100644 --- a/base/.zshenv +++ b/base/.zshenv @@ -2,9 +2,6 @@ export ZDOTDIR=${XDG_CONFIG_HOME:-~/.config}/zsh -### load site-specific -[[ -f ${ZDOTDIR:-~}/.zshenv.local ]] && source ${ZDOTDIR:-~}/.zshenv.local - ### fix broken term if [[ ! -v TERM ]] { TERM=xterm-256color >/dev/null 2>&1 @@ -27,6 +24,7 @@ if [[ ! -v _sev_first_display && ( -v DISPLAY || -v WAYLAND_DISPLAY ) ]] { _sev_refresh_gpgagent= [[ ! -o login ]] && source ${ZDOTDIR:-~}/.zprofile } elif [[ ! -o login && $SHLVL -eq 1 && ${+TERMUX_VERSION} -eq 0 ]] { - ### early zprofile sourcing for first shell even if not a login shell + ### early zprofile sourcing for first shell even if not a login shell, + ### since Termux does not start login shell as first process source ${ZDOTDIR:-~}/.zprofile } diff --git a/etc/zsh/.zlogin b/etc/zsh/.zlogin index 8b4aab6..e649935 100644 --- a/etc/zsh/.zlogin +++ b/etc/zsh/.zlogin @@ -1,7 +1,7 @@ # NOTE: all logic here moved to .zprofile, see comments there for rationale ### load site-specific -if [[ -f ${ZDOTDIR:-~}/.zlogin.local ]] { source ${ZDOTDIR:-~}/.zlogin.local } +load-site-dotfile zlogin ### cd for convenience cd ${_sev_home:-~} diff --git a/etc/zsh/.zlogout b/etc/zsh/.zlogout index cac7939..c005421 100644 --- a/etc/zsh/.zlogout +++ b/etc/zsh/.zlogout @@ -16,4 +16,4 @@ if [[ -o interactive ]] { } ### load site-specific -if [[ -f ${ZDOTDIR:-~}/.zlogout.local ]] { source ${ZDOTDIR:-~}/.zlogout.local } +load-site-dotfile zlogout diff --git a/etc/zsh/.zprofile b/etc/zsh/.zprofile index d9c05b3..4f11459 100644 --- a/etc/zsh/.zprofile +++ b/etc/zsh/.zprofile @@ -62,10 +62,6 @@ function _sev_zcleanup { unset x p y } -### lang -export CHARSET=${CHARSET:-UTF-8} -export LANG=${LANG:-en_US.UTF-8} - ### path # NOTE: we utilize the fact that unique arrays keep the first occurrence and # remove any further occurences to capture elements from the old PATH @@ -103,6 +99,17 @@ if [[ ! -v _sev_setup_path || -o login ]] { export _sev_setup_path= } +### autoload to load site specific dotfiles now that fpath is set +autoload -Uz load-site-dotfile + +### load zshenv site-specific +# NOTE: this has to be here since fpath isn't set in .zshenv +load-site-dotfile zshenv + +### lang +export CHARSET=${CHARSET:-UTF-8} +export LANG=${LANG:-en_US.UTF-8} + ### xdg local dir # NOTE: need this for tmp, so confirm it exists. # XXX: perms are not specified for XDG dirs except runtime, but I think 760 @@ -430,4 +437,4 @@ unfunction _gpg_socketpath ### load site-specific -if [[ -f ${ZDOTDIR:-~}/.zprofile.local ]] { source ${ZDOTDIR:-~}/.zprofile.local } +load-site-dotfile zprofile diff --git a/etc/zsh/.zshrc b/etc/zsh/.zshrc index 5b9c79a..6e5fcca 100644 --- a/etc/zsh/.zshrc +++ b/etc/zsh/.zshrc @@ -315,4 +315,4 @@ autoload -Uz promptinit && promptinit prompt arrows ### load site-specific -if [[ -f ${ZDOTDIR:-~}/.zshrc.local ]] { source ${ZDOTDIR:-~}/.zshrc.local } +load-site-dotfile zshrc diff --git a/etc/zsh/functions/Misc/load-site-dotfile b/etc/zsh/functions/Misc/load-site-dotfile new file mode 100644 index 0000000..275912d --- /dev/null +++ b/etc/zsh/functions/Misc/load-site-dotfile @@ -0,0 +1,10 @@ +# load site-specific dotfiles + +emulate -L zsh + +local x p +typeset -aU p +p=({${ZDOTDIR:-~},~}/{.,}${1#.}.local) +for x ($p) { + [[ -f $x ]] && source $x +} -- 2.47.0