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