]> git.sev.monster Git - dotfiles.git/blame_incremental - etc/zsh/.zshenv
.zshrc: don't override graphical mode env vars
[dotfiles.git] / etc / zsh / .zshenv
... / ...
CommitLineData
1### critical exports, the rest are in zprofile
2export CHARSET=${CHARSET:-UTF-8}
3export LANG=${LANG:-en_US.UTF-8}
4## alternative home for pulling in bin & config, used for zsu
5[[ -v _sev_home ]] || export _sev_home=$HOME
6
7## fix broken term
8# NOTE: we do this here instead of .zshrc since we might echo stuff
9if [[ -t 1 ]] { # only if stdout is tty
10 [[ ! -v TERM ]] && export TERM=xterm-256color >/dev/null 2>&1
11 if [[ $#terminfo -eq 0 ]] {
12 _oldterm=$TERM
13 export TERM=xterm >/dev/null 2>&1
14 [[ -o interactive ]] &&
15 print -P "%F{red}!!! Can't find terminfo for $_oldterm, using $TERM%f"
16 unset _oldterm
17 }
18}
19
20## path
21# NOTE: we utilize the fact that unique arrays keep the first occurrence and
22# remove any further occurences to capture elements from the old PATH
23# that we did not anticipate and shift them to the front, since they are
24# probably important to the system
25if [[ ! -v _sev_setup_path || -o login ]] {
26 typeset -U path fpath
27 # add as many generic paths as possible to keep the order we want
28 # NOTE: /usr/{local,pkg,games} are unix/bsdisms
29 # XXX: PREFIX not validated, non-posix but Termux uses it, maybe others
30 # XXX: XDG specifies ~/.local/bin as the only user-writable dir for
31 # executables, but we specify more; technically this is against spec
32 syspath=("$path[@]")
33 path=({{${_sev_home:-~},~}{/.local,},{$PREFIX,}{,/opt,/usr{,/local,/pkg}}}/{s,}bin
34 /usr/{X11R{7,6}/bin,games})
35 ((len=$#path))
36 path=("$path[@]" "$syspath[@]")
37 # remove bad paths
38 for (( i = 1; i <= $#path; i++ )) {
39 if [[ ! -d $path[$i] ]] {
40 path[$i]=()
41 ((i <= len)) && ((len--))
42 ((i--))
43 continue
44 }
45 }
46 # shift valid system paths to the front if there are any left
47 ((len > 0 && len < $#path)) && path=("${(@)path[len + 1, -1]}" "${(@)path[1, len]}")
48 unset syspath len i
49 # include our zsh dir in fpath. unlike above, we always prefer our paths
50 fpath=({${ZDOTDIR:-~/.zsh},{${_sev_home:-~},~}/.zsh}/functions/**/*(/N) "$fpath[@]")
51 # FPATH is not exported by default
52 export FPATH
53 typeset +U path fpath
54 export _sev_setup_path=
55}
56
57### load zshenv site-specific
58autoload -Uz load-site-dotfile
59load-site-dotfile zshenv
60
61### source .zprofile early for non-login shells to fix issues
62if [[ ! -v _sev_first_display && ( -v DISPLAY || -v WAYLAND_DISPLAY ) ]] {
63 # most graphical login/session managers will spawn the user's shell as a
64 # parent of all child processes for that session. however, if the parent shell
65 # isn't a login shell for some reason, our .zprofile won't be run, and the
66 # environment won't be configured for child processes.
67 #
68 # XXX: .zprofile will be sourced by every new child shell if zsh is not
69 # used to start the graphical session and the _sev_first_display var
70 # isn't exported; for example, this previously happened when using
71 # sway without a display manager in front of it to run a login shell.
72 #
73 # this issue is not mitigated by .zprofile only loading what has not
74 # already been loaded if the env vars preventing the load are not set;
75 # in that case, every shell will think it is a fresh login shell.
76
77 # update gpgagent to use graphical pinentry
78 # XXX: will steal display from any other logged in graphical sessions, but
79 # I consider this to be an unlikely scenario
80 _sev_refresh_gpgagent=
81
82 export _sev_first_display=
83 [[ ! -o login ]] && source ${ZDOTDIR:-~}/.zprofile
84} elif [[ ${+TERMUX_VERSION} -eq 0 && ! -o login && $SHLVL -eq 1 ]] {
85 ## Termux first process isn't login shell, so source early
86 source ${ZDOTDIR:-~}/.zprofile
87}
This page took 0.03088 seconds and 4 git commands to generate.