X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/8d4a98e19ec40334ed8e8f2ce4e5a9f094bdbcaf..2bf94bab09ba81e82c23467dcc6260f11e2cf659:/etc/zsh/.zprofile diff --git a/etc/zsh/.zprofile b/etc/zsh/.zprofile index 777e0fa..4f11459 100644 --- a/etc/zsh/.zprofile +++ b/etc/zsh/.zprofile @@ -11,12 +11,7 @@ # properly configured for any child processes. # * some desktop environments/graphical terminal emulators will start new # terminal windows with login shells, which runs .zprofile every time and -# leads to noticably slow startup times. -# * switching users without wiping the environment will result in paths and -# variables intended for the old user being used for the new user. while -# this may be considered an edge-case that should not be supported, there -# are legitimate reasons to want to do this, and in any case the shell -# should not choke or cause unexpected problems should it happen anyway. +# leads to noticably slow startup times if we have not already ran it. ### cleanup # XXX: only call after relevant vars have been set up, defined early so that @@ -67,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 @@ -84,9 +75,7 @@ if [[ ! -v _sev_setup_path || -o login ]] { # XXX: XDG specifies ~/.local/bin as the only user-writable dir for # executables, but we specify more; technically this is against spec syspath=("$path[@]") - path=(~/{.local/,}{s,}bin - {~/.local,{$PREFIX,}{,/opt,/usr{,/local,pkg}}}/sbin - {~/.local,{$PREFIX,}{,/opt,/usr{,/local,pkg}}}/bin + path=({{${_sev_home:-~},~}{/.local,},{$PREFIX,}{,/opt,/usr{,/local,/pkg}}}/{s,}bin /usr/{X11R{7,6}/bin,games}) ((len=$#path)) path=("$path[@]" "$syspath[@]") @@ -110,12 +99,23 @@ 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 # makes the most sense. shouldn't break anything since no one else should # be poking around in our dir. -[[ -e ~/.local ]] || mkdir -m760 ~/.local +[[ -e ${_sev_home:-~}/.local ]] || mkdir -m760 ${_sev_home:-~}/.local ### tmp # NOTE: specs say that POSIX tmp and XDG runtime directories should exist @@ -125,7 +125,7 @@ if [[ ! -v _sev_setup_path || -o login ]] { # toplevel session (i.e. SHLVL=1). this should placate most applications, # though it is not expressly spec compliant. if [[ ! -v _sev_tmp ]] { - _sev_tmp=~/.local/tmp + _sev_tmp=${_sev_home:-~}/.local/tmp # NOTE: race condition/remove in use files [[ -h $_sev_tmp ]] && unlink $_sev_tmp 2>/dev/null t=${TMPDIR:-${TEMP:-${TMP:-/tmp}}}/.home-$LOGNAME @@ -202,7 +202,9 @@ if [[ ! -v _sev_setup_xdg ]] { mkdir -m760 ~/.local/state } - if [[ ! -v XDG_CACHE_HOME ]] { + 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 @@ -211,15 +213,19 @@ if [[ ! -v _sev_setup_xdg ]] { } } - # 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 - if [[ -h $XDG_RUNTIME_DIR ]] { - unlink $XDG_RUNTIME_DIR 2>/dev/null - } elif [[ -e $XDG_RUNTIME_DIR ]] { - rm -rf $XDG_RUNTIME_DIR 2>/dev/null + if [[ -v XDG_RUNTIME_DIR ]] { + export XDG_RUNTIME_DIR + } 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 + if [[ -h $XDG_RUNTIME_DIR ]] { + unlink $XDG_RUNTIME_DIR 2>/dev/null + } elif [[ -e $XDG_RUNTIME_DIR ]] { + rm -rf $XDG_RUNTIME_DIR 2>/dev/null + } + mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null } - mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null # source user dirs after other vars [[ -e $XDG_CONFIG_HOME/user-dirs.dirs ]] && @@ -347,8 +353,9 @@ if [[ -v commands[gpg-connect-agent] && ${+DISPLAY} + ${+WAYLAND_DISPLAY} == 0)) # XXX: don't know if gpg-agent supports comments after directives # XXX: path could have # + # XXX: we are assuming this is our pinentry from .local/bin sed -Ei 's#^([[:space:]]*pinentry-program[[:space:]]).*$#\1'${commands[pinentry]:-/dev/null}'#' \ - ${GNUPGHOME:-~/.gnupg}/gpg-agent.conf + ${GNUPGHOME:-~/.gnupg}/gpg-agent.conf 2>/dev/null # XXX: could check for changes before doing this to save perf gpg-connect-agent RELOADAGENT UPDATESTARTUPTTY /bye >/dev/null 2>&1 if {$p} { @@ -430,6 +437,4 @@ unfunction _gpg_socketpath ### load site-specific -if [[ -f ${ZDOTDIR:-~}/.zprofile.local ]] { source ${ZDOTDIR:-~}/.zprofile.local } - -# vim: et sts=4 sw=4 ts=8 tw=79 +load-site-dotfile zprofile