X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/8a92a2c03c1ea03829e44bf80771a08153261e2a..ef32cb1c2ed740bba5cdbc1f9105233e99b3c106:/etc/zsh/.zshenv diff --git a/etc/zsh/.zshenv b/etc/zsh/.zshenv index 56f80dc..1248dbf 100644 --- a/etc/zsh/.zshenv +++ b/etc/zsh/.zshenv @@ -3,6 +3,8 @@ # XXX: only call after relevant vars have been set up, defined early so that # below code can utilize it after they do so function _sev_zcleanup { + local x p y + # gpg forwarding if [[ -d $_sev_gpg_forward_dir && ( -z $1 || $1 == 'gpg-forward' ) ]] { # clean up forward dirs if its session is dead or we ask for it @@ -25,7 +27,7 @@ function _sev_zcleanup { } } # reset GNUPGHOME if we removed our own dir - if [[ $GNUPGHOME =~ '/.ssh_forward/\d+/*$' && ! -e $GNUPGHOME ]] + if [[ $GNUPGHOME =~ '/.ssh_forward/\d+/*$' && ! -d $GNUPGHOME ]] GNUPGHOME=${GNUPGHOME%$MATCH} } @@ -46,27 +48,31 @@ function _sev_zcleanup { } } } - - unset x p y } function _sev_setpath { - # 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 - 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 + # NOTE: tied arrays path and fpath already exist, but are not unique (-U); + # we utilize the fact that unique arrays keep the first occurrence + # and remove any further occurences to check for elements from the + # old PATH that we did not anticipate and shift them to the front, + # since they are probably important to the system + typeset -gU path fpath + local -a syspath=("$path[@]") + # NOTE: /usr/{pkg,games} are unix/bsdisms + # NOTE: some systems (esp. research machines) may have multiple versions of + # packages installed in /opt/[pkg]/[ver]/bin or other dirs, managed + # with something like Environment Modules. this code does not account + # for this type of usage and will add all valid paths. any undesired + # paths can be removed using .zshenv.local. + # 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 + path=({{${_sev_home:-~},~}{/.local,},{$PREFIX,}{,/usr{,/local,/pkg},/opt{,/*{/*,}}}}/{s,}bin(N) {$PREFIX,}/usr/{X11R{7,6}/bin,games} # emulate Arch Linux flatpak-bindir.sh for use on other systems {${XDG_DATA_HOME:-~/.local/share},{$PREFIX,}/var/lib}/flatpak/exports/bin) - ((len=$#path)) + local -i i len=$#path path=("$path[@]" "$syspath[@]") # remove bad paths for (( i = 1; i <= $#path; i++ )) { @@ -91,8 +97,8 @@ function _sev_setpath { } # FPATH is not exported by default export FPATH + # un-unique system arrays for consistency typeset +U path fpath - unset syspath len i } ### common exports @@ -103,7 +109,7 @@ export LANG=${LANG:-en_US.UTF-8} [[ -v _sev_home ]] || export _sev_home=$HOME ## fix broken term -# NOTE: we do this here instead of .zshrc since we might echo stuff +# NOTE: we do this here instead of .zshrc since we might print stuff if [[ -t 1 ]] { # only if stdout is tty [[ ! -v TERM ]] && export TERM=xterm-256color >/dev/null 2>&1 if [[ $#terminfo -eq 0 ]] { @@ -149,7 +155,7 @@ if [[ ! -v _sev_setup_path || -o login ]] { # chances of that are slim. if [[ ! -v _sev_tmp ]] { # create personal TMPDIR under system tmp - t=${TMPDIR:-${TEMPDIR:-${TEMP:-${TMP:-/tmp}}}}/.home-$LOGNAME + t=${TMPDIR:-${TEMPDIR:-${TEMP:-${TMP:-${${TMPPREFIX%/zsh}:-/tmp}}}}}/.home-$LOGNAME [[ -e $t ]] || mkdir -m700 $t 2>/dev/null _sev_tmp=~/.local/tmp if [[ ! -d $t ]] { @@ -188,7 +194,7 @@ if [[ ! -v _sev_tmp ]] { print -P "%F{red}!!! Can't create session tmp subdir $t, using $_sev_tmp%f" t=$_sev_tmp fi - export _sev_tmp TMPDIR=$t TEMPDIR=$t TEMP=$t TMP=$t + export _sev_tmp TMPDIR=$t TEMPDIR=$t TEMP=$t TMP=$t TMPPREFIX=$t/zsh } unset t } @@ -205,7 +211,7 @@ if [[ ! -v _sev_setup_xdg ]] { # include any of the below dirs there, but you never know what crazy shit # people will do. I rather handle them sanely with our own code than let # them override after the fact. - [[ -e $XDG_CONFIG_HOME/user-dirs.dirs ]] && + [[ -f $XDG_CONFIG_HOME/user-dirs.dirs ]] && emulate sh -c "source $XDG_CONFIG_HOME/user-dirs.dirs" typeset -UT XDG_DATA_DIRS xdg_data_dirs @@ -215,8 +221,7 @@ if [[ ! -v _sev_setup_xdg ]] { mkdir -m760 ~/.local/share } xdg_data_dirs=($XDG_DATA_HOME /{opt,usr/local,usr/pkg,usr}/share - ${XDG_DATA_DIRS:+"$xdg_data_dirs[@]"}) - xdg_data_dirs=${xdg_data_dirs:#} + ${XDG_DATA_DIRS:+${xdg_data_dirs%%/}}) export XDG_DATA_DIRS typeset -UT XDG_CONFIG_DIRS xdg_config_dirs @@ -227,9 +232,9 @@ if [[ ! -v _sev_setup_xdg ]] { } # I am of the belief .local should follow FHS /usr/local... [[ -e ~/.local/etc ]] || ln -s ~/.config ~/.local/etc - xdg_config_dirs=($XDG_CONFIG_HOME ${XDG_CONFIG_DIRS:+"$xdg_config_dirs[@]"} + xdg_config_dirs=($XDG_CONFIG_HOME + ${XDG_CONFIG_DIRS:+${xdg_config_dirs%%/}} {/opt,/usr/local,/usr/pkg,}/etc/xdg) - xdg_config_dirs=${xdg_config_dirs:#} export XDG_CONFIG_DIRS if [[ -v XDG_STATE_HOME ]] { @@ -287,6 +292,12 @@ if [[ ! -v GNUPGHOME ]] { eval $(perl -I$XDG_DATA_HOME/perl5/lib/perl5 \ -Mlocal::lib=$XDG_DATA_HOME/perl5 2>/dev/null) +## go +if [[ -v commands[go] ]] { + [[ ! -v GOPATH ]] && export GOPATH=${XDG_DATA_HOME:-~/.local/share}/go:~/go + [[ ! -v GOBIN ]] && export GOBIN=~/.local/bin +} + ### load zshenv site-specific autoload -Uz load-site-dotfile load-site-dotfile zshenv