-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.shared_env
278 lines (215 loc) · 5.9 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/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
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:-0}" -ge 2 ]; then
debug="\n"
fi
# \e[0K is clear to right
if [ -n "$shell_interactive" ]; 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
# }}}
# {{{ HOME
# Don't leave history files in /
: ${HOME:=/}
if [ "$HOME" = '/' ]; then
if [ -d /root ]; then
HOME=/root
elif [ -d /var/tmp ]; then
new_home=/var/tmp/root.tmphome
if [ -d "$new_home" ] || mkdir "$new_home"; then
HOME="$new_home"
fi
fi
fi
[ "$HOME" = '/' ] && echo "Warning: ~ is /"
# }}}
# {{{ 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/X11R6/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 \
$dir/local/$OSTYPE/bin \
$dir/local/sbin \
$dir/local/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
# }}}
# {{{ grep
# Why would you ever want grep to treat dirs like normal files?
export GREP_OPTIONS='--directories=skip'
# }}}
# {{{ GNU screen
case "$TERM" in
screen*) IN_SCREEN=yes ; export IN_SCREEN ;;
esac
export SCREENRC=$ZDOTDIR/.screenrc
# }}}
# {{{ INPUTRC
# no crappy RedHat inputrcs, thankyouverymuch. Which fucking *idiot*
# set convert-meta to off?
[ -n "$INPUTRC" ] && unset INPUTRC
# }}}
# {{{ COLUMNS
# Some programs find this handy. Unfortunately xterm gets confused
# when launched with it set ...
export COLUMNS
# }}}
# {{{ OSTYPE
# Can come in handy too, if the shell sets it (bash and zsh do).
export OSTYPE
# }}}
# {{{ Pager
export METAMAIL_PAGER='less -r'
export PERLDOC_PAGER='less -r'
export PAGER='less'
export LESS='-a -h100 -i -j15 -J -M -q -W -y100'
export LESSOPEN="|$ZDOTDIR/bin/lesspipe.sh %s"
#export LESSCLOSE='/usr/local/bin/lessclose.sh %s %s'
# Make sure synced with .cfg-post.d/shell-env
export LESSKEY="$ZDOTDIR/.less"
# }}}
# {{{ POSIXLY_CORRECT for patch
#export POSIXLY_CORRECT=yes
# }}}
# {{{ Commonly used files and directories
# Have cdable_vars set in zsh, so don't need 'hash -d' in front of these
# and can be reused from any shell
if [ -n "$shell_interactive" ]; then
SC=/etc/sysconfig
SCN=/etc/sysconfig/network
if [ -d /etc/sysconfig/network-scripts ]; then
NS=/etc/sysconfig/network-scripts
elif [ -d "$SCN" ]; then
NS=$SCN
fi
RCD=/etc/rc.d
ID=/etc/init.d # LSB
RC0=$RCD/rc0.d
RC1=$RCD/rc1.d
RC2=$RCD/rc2.d
RC3=$RCD/rc3.d
RC4=$RCD/rc4.d
RC5=$RCD/rc5.d
RC6=$RCD/rc6.d
VL=/var/log
VLH=$VL/httpd
VM=$VL/messages
US=/usr/src
KES=/usr/src/kernels
KE=/lib/modules/`uname -r`/build
# in zsh:
#hash -df
RC=/etc/resolv.conf
if [ -f /boot/grub/menu.lst ]; then
GC=/boot/grub/menu.lst
else
GC=/etc/grub.conf
fi
FS=/etc/fstab
fi
# }}}
. $ZDOT_RUN_HOOKS .shared_env.d
shared_env_loaded=y