]> git.sev.monster Git - dotfiles.git/blame - base/.zshenv
reorganize aliases, clean up binds, add zoxide
[dotfiles.git] / base / .zshenv
CommitLineData
f11fbf9e 1### unset unwanted options that could be set in /etc/zshenv
2unsetopt SH_WORD_SPLIT KSH_ARRAYS
3
4### check if su
5if [[ -v _sev_olduser && $_sev_olduser != $USERNAME ]] _sev_reset_shell=
6export _sev_olduser=$USERNAME
7
8### exports for all new shells
9if [[ -v _sev_reset_shell || $SHLVL == 1 ]] {
b133dc92 10 ## lang
11 export CHARSET=UTF-8
f11fbf9e 12 export LANG=en_US.UTF-8
13 export LC_CTYPE=$LANG
b133dc92 14
15 ## path
f11fbf9e 16 typeset -U path fpath
17 if [[ $SHLVL == 1 ]] {
18 # take a backup before any customizations
19 export _sev_sys_PATH=$PATH
20 export _sev_sys_FPATH=$FPATH
21 }
b133dc92 22 # /usr/{pkg,local,games} are unix/bsdisms
b133dc92 23 path=({~/,/,/usr/}sbin {~/,/,/usr/}bin /usr/pkg/{s,}bin /usr/X11R{7,6}/bin
f11fbf9e 24 /usr/local/{s,}bin /usr/games)
25 PATH=$PATH:$_sev_sys_PATH
26 fpath=(${ZDOTDIR:-$HOME/.zsh}/functions/{*,Completions/*}(N))
bdeaf2f0 27 #fpath is not exported by default
28 export FPATH=$FPATH:$_sev_sys_FPATH
f11fbf9e 29 # take another backup, explained in .zprofile
30 typeset -U _backup_path
31 _backup_path=("${path[@]}")
b133dc92 32
33 ## xdg
34 export XDG_CONFIG_HOME=~/etc
35 export XDG_CONFIG_DIRS=~/.config:/usr/pkg/etc/xdg:/usr/local/etc/xdg:/etc/xdg
36 export XDG_DATA_HOME=~/share
37 export XDG_DATA_DIRS=~/.local/share:/usr/pkg/share:/usr/local/share:/usr/share
38 export XDG_CACHE_HOME=~/tmp
39 export XDG_RUNTIME_DIR=~/tmp
3b9bd321 40 if [[ -e $XDG_CONFIG_HOME/user-dirs.dirs ]] {
41 source $XDG_CONFIG_HOME/user-dirs.dirs
42 }
b133dc92 43
f11fbf9e 44 ## create tmp link
45 t=${TMPDIR:-/tmp}/home-$LOGNAME
f11fbf9e 46 if [[ ! -e $t ]] {
ca5ceef3 47 mkdir -m 700 $t >/dev/null 2>&1
b133dc92 48 # TODO: check if dir exists after mkdir
49 }
50 # allow opaque entries to override link creation
466ae526 51 if [[ ! -e $XDG_RUNTIME_DIR ]] {
52 ln -sf $t $XDG_RUNTIME_DIR >/dev/null 2>&1
b133dc92 53 }
466ae526 54 unset t
b133dc92 55
f11fbf9e 56 ## ssh agents
57 # NOTE: preferred order of agents to check: okcagent, gnupg, openssh
58 # first block takes care of okcagent and openssh, second gnupg
f72da500 59 [[ -o interactive ]] && print -nP "%F{blue}>>>%f SSH: %F{green}"
f11fbf9e 60 if [[ ! -v SSH_AUTH_SOCK && ( -v commands[okc-ssh-agent] ||
61 ( -v commands[ssh-agent] && ! -v commands[gpg] ) ) ]] {
62 okc=${commands[okc-ssh-agent]:+okc-}
63 agentfile=~/tmp/${okc}ssh-agent-exports
64 typeset sock=
65 typeset -i pid=
66 if [[ -f $agentfile ]] {
67 IFS=$'\0' read -r sock pid <$agentfile
68 }
69 if [[ -S $sock && $pid > 0 ]] && kill -0 $pid; then
ca5ceef3 70 [[ -o interactive ]] && echo "Reusing agent pid $pid"
f11fbf9e 71 export SSH_AUTH_SOCK=$sock
72 export SSH_AGENT_PID=$pid
73 else
74 # TODO: ensure ssh-agent path looks legit
75 # to avoid unsafe eval?
ca5ceef3 76 # NOTE: no way around doing redirection like this I think
77 e=${okc}ssh-agent
78 if [[ -o interactive ]] {
79 eval `$e`
80 } else {
81 eval `$e` >/dev/null 2>&1
82 }
f11fbf9e 83 echo -n $SSH_AUTH_SOCK$'\0'$SSH_AGENT_PID >!$agentfile
84 fi
85 unset okc agentfile sock pid
86 } elif [[ -v commands[gpg] && ! -S $_GNUPG_SOCK_DEST && \
87 ( ! -v SSH_AUTH_SOCK || -v DISPLAY ) ]] {
88 export GPG_TTY=$(tty)
89 export PINENTRY_USER_DATA=USE_TTY=$((!${+DISPLAY}))
90 gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null 2>&1
ca5ceef3 91 [[ -o interactive ]] && gpg-connect-agent /subst /serverpid \
f11fbf9e 92 '/echo GPG agent pid ${get serverpid}' /bye
93 [[ ! -v SSH_AUTH_SOCK ]] && \
94 export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
95 } else {
ca5ceef3 96 [[ -o interactive ]] && echo "Pre-existing or remote agent"
f11fbf9e 97 }
98
99 ## gpg ssh forwarding
100 # ssh automatically tunnels SSH_AUTH_SOCK with the right config, but GPG
101 # doesn't—we use a RemoteForward rule in ~/.ssh/config that uses these env
102 # vars to push the gpg extra socket through when connecting via ssh
103 # HACK: this entire thing sucks but there is no other easy way that works
104 # out of the box with other systems
105 if [[ -v commands[gpgconf] ]] {
106 # if already connected over SSH, reuse forwarded socket for future
107 # connections; else use extra socket
108 sock=${SSH_CLIENT:+agent-socket}
109 export _GNUPG_SOCK_SRC=$(gpgconf --list-dirs ${sock:-agent-extra-socket})
110 unset sock
111 # XXX: multiple SSH sessions to the same host will overwrite this
112 # socket, no way to send unique paths without configuring explicit
113 # SendEnv and AcceptEnv exclusions on client and host respectively
114 export _GNUPG_SOCK_DEST=/tmp/.gpg-agent-forward
115 # if socket exists already, we are on a RemoteForwarded client, so copy
116 # it over so that GPG sees it
117 # XXX: race condition if connecting multiple terminals at once
118 if [[ -S $_GNUPG_SOCK_DEST ]] {
119 unlink $_GNUPG_SOCK_SRC >/dev/null 2>&1
120 mv $_GNUPG_SOCK_DEST $_GNUPG_SOCK_SRC >/dev/null
121 }
122 }
b133dc92 123}
124
f7960c69 125### load site-specific
81c3957e 126if [[ -f ~/.zshenv.local ]] { source ~/.zshenv.local }
127
f11fbf9e 128### source .zprofile
129# if we used su, without --login, let's run zprofile ourselves
130# XXX: system zprofile is not run
131if [[ -v _sev_reset_shell || $SHLVL == 1 ]] source ~/.zprofile
132
81c3957e 133# vim: set et sts=4 sw=4 ts=8 tw=79 :
This page took 0.069544 seconds and 4 git commands to generate.