# Filename: ~/.zshenv # Purpose: config file for zsh (z shell) # Authors: Dennis Eriksen # License: This file is licensed under the BSD-3-Clause license. ################################################################################ # This file is sourced on all invocations of the shell. It is the 1st file zsh # reads from the user directory. # # This file should contain commands to set the command search path, plus other # important environment variables. This file should not contain commands that # produce output or assume the shell is attached to a tty. # # Notice: .zshenv is not read if zsh is started with -f # # Global Order: zshenv, zprofile, zshrc, zlogin, zlogout # Specific order: /etc/zshenv, $ZDOTDIR/.zshenv, /etc/zprofile, # $ZDOTDIR/.zprofile, /etc/zshrc, $ZDOTDIR/.zshrc, /etc/zlogin, # $ZDOTDIR/.zlogin, $ZDOTDIR/.zlogout, /etc/zlogout ################################################################################ # # ### Some global options ######################## # # # https://zsh.sourceforge.io/Doc/Release/Options.html unsetopt global_rcs # Do not load /etc/zsh/zprofile, /etc/zsh/zshrc, /etc/zsh/zlogin, and /etc/zsh/zlogout # # ### Environment ######################## # # # XDG https://specifications.freedesktop.org/basedir-spec/latest/ : ${XDG_CONFIG_HOME:=~/.config} : ${XDG_CACHE_HOME:=~/.cache} : ${XDG_DATA_HOME:=~/.local/share} : ${XDG_RUNTIME_DIR:=/run/user/$UID} : ${XDG_STATE_HOME:=~/.local/state} export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME # ZDIRS export ZDOTDIR=~/.zsh export ZCACHEDIR=$XDG_CACHE_HOME/zsh export ZDATADIR=$XDG_DATA_HOME/zsh export ZSTATEDIR=$XDG_STATE_HOME/zsh # TMPDIR if [[ -n $TMPDIR && -d $TMPDIR && -w $TMPDIR ]]; then export TMPDIR=${TMPDIR%/} elif [[ $OSTYPE == linux* && -d /run/user/$UID && -O /run/user/$UID ]]; then export TMPDIR=/run/user/$UID elif [[ -d /tmp && -w /tmp ]]; then export TMPDIR=/tmp else print -u2 "No TMPDIR can be found. WTF? Defaulting to ~/tmp" export TMPDIR=~/tmp fi export TMPPREFIX=$TMPDIR/zsh # Check XDG_RUNTIME_DIR [[ $XDG_RUNTIME_DIR == $TMPDIR ]] || XDG_RUNTIME_DIR=$TMPDIR/$UID-runtime # Link infopath. The rest of the paths are set and linked by zsh. typeset -T INFOPATH infopath # Make sure all these variables only contain unique values # The ZSH-manual has this to say about the -U-flag: # Note the flag takes effect on assignment, and the type of the variable # being assigned to is determinative; for variables with shared values it is # therefore recommended to set the flag for all interfaces, e.g. ‘typeset -U # PATH path’. typeset -U path PATH \ fpath FPATH \ cdpath CDPATH \ manpath MANPATH \ infopath INFOPATH # Export paths as they are set. No reason to export empty values. # globs used in path and fpath # (-/N:A) are glob qualifiers for filename generation, and a modifier # - makes operators work on symbolic links # / only matches directories (that exist) # N sets the NULL_GLOB option for current pattern, i.e., returns nothing # instead of an error if pattern does not match anything. # :A is a modifier, and expands file-/dirnames into absolute paths. Modifiers work within parameter expansion as well as glob qualifiers # See here for more info: # https://zsh.sourceforge.io/Doc/Release/Expansion.html#Globbing-Flags # https://zsh.sourceforge.io/Doc/Release/Expansion.html#Modifiers # PATH path=( ~'/bin'(-/N:A) '/usr/local/bin'(-/N:A) '/usr/local/sbin'(-/N:A) '/usr/bin'(-/N:A) '/usr/sbin'(-/N:A) '/bin'(-/N:A) '/sbin'(-/N:A) ${^path}(-/N:A) ) [[ $OSTYPE == darwin* ]] && path=( ~'/bin'(-/N:A) # throw in ~/bin again here, to make sure it's first in your $path '/opt/homebrew/opt/coreutils/libexec/gnubin'(-/N:A) # give us coreutils in $path on macOS '/opt/homebrew/opt/curl/bin'(-/N:A) # use curl from homebrew, if available '/opt/homebrew/bin'(-/N:A) '/opt/homebrew/sbin'(-/N:A) $path ) [[ $OSTYPE == openbsd* ]] && path+=( '/usr/X11R6/bin'(-/N:A) '/usr/X11R6/sbin'(-/N:A) ) (( UID > 0 )) && path+=( '/usr/local/games'(-/N:A) '/usr/games'(-/N:A) ) # don't want games as root export PATH # PATH is exported by default, but it's better to be explicit. # FPATH fpath=( "${ZDOTDIR}/functions"(-/N:A) "${ZCACHEDIR}/misc_functions.zwc"(-.N:A) "${ZDATADIR}/completion"(-/N:A) '/usr/local/share/zsh-completions'(-/N:A) '/usr/local/share/zsh/site-functions'(-/N:A) '/usr/share/zsh/vendor-completions'(-/N:A) '/opt/homebrew/share/zsh-completions'(-/N:A) '/opt/homebrew/share/zsh/site-functions'(-/N:A) ${^fpath}(-/N:A) ) export FPATH # Make sure FPATH is actually in your env ## END OF FILE ################################################################