+### critical exports, the rest are in zprofile
+export CHARSET=${CHARSET:-UTF-8}
+export LANG=${LANG:-en_US.UTF-8}
+## alternative home for pulling in bin & config, used for zsu
+[[ -v _sev_home ]] || export _sev_home=$HOME
+
+## fix broken term
+# NOTE: we do this here instead of .zshrc since we might echo stuff
+if [[ -t 1 ]] { # only if stdout is tty
+ [[ ! -v TERM ]] && export TERM=xterm-256color >/dev/null 2>&1
+ if [[ $#terminfo -eq 0 ]] {
+ _oldterm=$TERM
+ export TERM=xterm >/dev/null 2>&1
+ [[ -o interactive ]] &&
+ print -P "%F{red}!!! Can't find terminfo for $_oldterm, using $TERM%f"
+ unset _oldterm
+ }
+}
+
+## 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
+# that we did not anticipate and shift them to the front, since they are
+# probably important to the system
+if [[ ! -v _sev_setup_path || -o login ]] {
+ typeset -U path fpath
+ # add as many generic paths as possible to keep the order we want
+ # NOTE: /usr/{local,pkg,games} are unix/bsdisms
+ # XXX: PREFIX not validated, non-posix but Termux uses it, maybe others
+ # 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=({{${_sev_home:-~},~}{/.local,},{$PREFIX,}{,/opt,/usr{,/local,/pkg}}}/{s,}bin
+ /usr/{X11R{7,6}/bin,games})
+ ((len=$#path))
+ path=("$path[@]" "$syspath[@]")
+ # remove bad paths
+ for (( i = 1; i <= $#path; i++ )) {
+ if [[ ! -d $path[$i] ]] {
+ path[$i]=()
+ ((i <= len)) && ((len--))
+ ((i--))
+ continue
+ }
+ }
+ # shift valid system paths to the front if there are any left
+ ((len > 0 && len < $#path)) && path=("${(@)path[len + 1, -1]}" "${(@)path[1, len]}")
+ unset syspath len i
+ # include our zsh dir in fpath. unlike above, we always prefer our paths
+ fpath=({${ZDOTDIR:-~/.zsh},{${_sev_home:-~},~}/.zsh}/functions/**/*(/N) "$fpath[@]")
+ # FPATH is not exported by default
+ export FPATH
+ typeset +U path fpath
+ export _sev_setup_path=
+}
+
+### load zshenv site-specific
+autoload -Uz load-site-dotfile
+load-site-dotfile zshenv
+
+### source .zprofile early for non-login shells to fix issues
+if [[ ! -v _sev_first_display && ( -v DISPLAY || -v WAYLAND_DISPLAY ) ]] {
+ # most graphical login/session managers will spawn the user's shell as a
+ # parent of all child processes for that session. however, if the parent shell
+ # isn't a login shell for some reason, our .zprofile won't be run, and the
+ # environment won't be configured for child processes.
+ #
+ # XXX: .zprofile will be sourced by every new child shell if zsh is not
+ # used to start the graphical session and the _sev_first_display var
+ # isn't exported; for example, this previously happened when using
+ # sway without a display manager in front of it to run a login shell.
+ #
+ # this issue is not mitigated by .zprofile only loading what has not
+ # already been loaded if the env vars preventing the load are not set;
+ # in that case, every shell will think it is a fresh login shell.
+
+ # update gpgagent to use graphical pinentry
+ # XXX: will steal display from any other logged in graphical sessions, but
+ # I consider this to be an unlikely scenario
+ _sev_refresh_gpgagent=
+
+ export _sev_first_display=
+ [[ ! -o login ]] && source ${ZDOTDIR:-~}/.zprofile
+} elif [[ ${+TERMUX_VERSION} -eq 0 && ! -o login && $SHLVL -eq 1 ]] {
+ ## Termux first process isn't login shell, so source early
+ source ${ZDOTDIR:-~}/.zprofile
+}