-
Notifications
You must be signed in to change notification settings - Fork 13
/
.shared_env
148 lines (117 loc) · 3.57 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
#!/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
# }}}
# {{{ 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/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/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
# }}}
. $ZDOT_RUN_HOOKS .shared_env.d
if [ -n "$shell_interactive" ]; then
. $ZDOTDIR/.shared_rc
fi
shared_env_loaded=y