-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.shared_env
218 lines (174 loc) · 5.18 KB
/
.shared_env
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/sh
#
# Adam's shared environment startup file
#
# $Id$
#
# This should get run as part of setting up the environment
# of any sh-compatible shell, including non-interactive ones;
# hence it should be kept as fast and as portable as possible.
# Note that that means silly things like [ ! -e foo ] rather
# than ! [ -e foo ] ...
# Allow disabling of entire environment suite
[ -n "$INHERIT_ENV" ] && return 0
[ -n "$shared_env_loaded" ] && return 0
# {{{ Are we interactive?
case "$-" in
*i*) shell_interactive=y ;;
*) shell_interactive= ;;
esac
# }}}
# {{{ Loading status
#[ "$shell" = -zsh ] && unsetopt function_argzero
# Default to 1, and treat empty as 0. This ensures we have an integer.
: ${DEBUG_LOCAL_HOOKS=1}
: ${DEBUG_LOCAL_HOOKS:=0}
sh_load_status () {
# Find the name of the running shell
_this_shell=${shell:-${0##*/}}
# Find the filename of the running script
if [ -n "$BASH_SOURCE" ]; then
_this_script="${BASH_SOURCE[0]}"
# Deduct 1 because array starts at 0, and another 1 because
# we want to ignore this stack frame (inside sh_load_status)
_this_script="${BASH_SOURCE[$(( ${#BASH_SOURCE[@]} - 2))]}"
# Sheesh. $ZSH_SOURCE[-2], anyone?
else
_this_script="$0"
# Unfortunately in zsh there seems to be no way of determining
# the currently running file if a function is being run, unless
# function_argzero is unset :-/
[ "$_this_script" = sh_load_status ] && _this_script=
[ "$_this_script" = -zsh ] && _this_script=
fi
[ -n "$_this_script" ] && _this_script="[$_this_script]"
# Leave status printed?
if [ "$DEBUG_LOCAL_HOOKS" -ge 2 ]; then
debug="\n"
fi
# \e[0K is clear to right
if [ -n "$shell_interactive" ] && [ "$TERM" != 'dumb' ]; then
_text="${_this_shell}${_this_script}: $*... "
_text="${_text//\/home\//~}"
echo -e -n "\r\e[0K$_text$debug"
fi
}
# }}}
sh_load_status .shared_env
# {{{ ZDOTDIR, ZDOTDIRPATH, ZDOTUSER
# See .zshenv
zdotdir=${ZDOTDIR:-$HOME}
ZDOTDIR="$zdotdir"
ZDOT_RUN_HOOKS="$ZDOTDIR/.zsh/functions/run_hooks"
ZDOT_FIND_HOOKS="$ZDOTDIR/.zsh/functions/find_hooks"
export ZDOTDIR ZDOT_RUN_HOOKS ZDOT_FIND_HOOKS
# Define a search path to be used by run_hooks
if [ "$ZDOTDIR" = "$HOME" ]; then
ZDOTDIRPATH=$ZDOTDIR
ZDOTDIRREVPATH=$ZDOTDIR
else
OTHER_USER=1
export OTHER_USER
ZDOTDIRPATH="$ZDOTDIR $HOME"
ZDOTDIRREVPATH="$HOME $ZDOTDIR"
fi
export ZDOTDIRPATH ZDOTDIRREVPATH
[ -z "$ZDOTUSER" ] && [ -e ~/.zdotuser ] && ZDOTUSER=`cat ~/.zdotuser`
export ZDOTUSER
# }}}
# {{{ HOST / HOSTNAME
: ${HOST:=${HOSTNAME:-`hostname`}}
: ${HOSTNAME:=$HOST}
# Let's not make this *too* sticky because dhcp might change the host
#export HOST HOSTNAME
# }}}
# {{{ USER / USERNAME
# zsh sets USERNAME, GROUPS, and E?[UG]ID
# bash only sets E?UID
USER=${USERNAME:-`id -un`}
: ${USERNAME:=$USER}
export USER USERNAME
# }}}
# {{{ PATH
# Don't trust system-wide PATH? Remember what it was, for reference.
syspath=$HOME/.syspath.$HOST
if [ ! -e $syspath ]; then
# Ignore failed write as home directory is sometimes locked down
# cross-WAN.
echo "$PATH" 2>/dev/null > "$syspath"
fi
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
# ... or *do* trust system-wide PATH
#PATH=/usr/local/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH
. $ZDOTDIR/.zsh/functions/enable_wordsplit
newpaths=
for dir in $ZDOTDIRREVPATH; do
for newpath in \
$dir/sbin \
$dir/bin \
; do
if [ -d $newpath ]; then
if [ -z "$newpaths" ]; then
newpaths=$newpath
else
newpaths=$newpaths:$newpath
fi
fi
done
done
restore_wordsplit
PATH=$newpaths:$PATH
# }}}
# {{{ MANPATH
# In order to avoid forks here, this is done in .zshrc
# }}}
# {{{ Perl libraries
export PERL5LIB
add_perl5lib_path () {
new_path="$1"
case "$PERL5LIB" in
'')
PERL5LIB=$new_path
;;
$new_path|*:$new_path|$new_path:*|*:$new_path:*)
: #echo "$newpaths already in \$PERL5LIB"
;;
*)
PERL5LIB=$new_path:$PERL5LIB
;;
esac
}
for dir in $ZDOTDIRREVPATH; do
add_perl5lib_path $dir/lib/perl5
add_perl5lib_path $dir/lib/perl5/site_perl
# # Use a cache to avoid invoking Perl during startup of every single
# # shell (even non-interactive ones).
# cachedir=$dir/.config/perl
# cache=$cachedir/pmdir_relative_path
# if [ -e $cache ]; then
# pmdir_relative_path=$(<$cache)
# else
# # This trick comes from Stow's configure.ac
# pmdir_relative_path=`
# perl -MConfig \
# -wle '($_ = $Config{installsitelib})
# =~ s!^\Q$Config{siteprefix}/!!; \
# print'`
# mkdir -p $cachedir
# echo "$pmdir_relative_path" > $cache
# fi
#
# if [ -n "$pmdir_relative_path" ]; then
# add_perl5lib_path $dir/$pmdir_relative_path
# fi
done
# }}}
# {{{ OSTYPE
# Can come in handy too, if the shell sets it (bash and zsh do).
export OSTYPE
# }}}
. $ZDOT_RUN_HOOKS .shared_env.d
if [ -n "$shell_interactive" ]; then
. $ZDOTDIR/.shared_rc
fi
shared_env_loaded=y