-
Notifications
You must be signed in to change notification settings - Fork 1
/
zenv.plugin.sh
58 lines (49 loc) · 1.3 KB
/
zenv.plugin.sh
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
#!/bin/sh
# TODO: If ZENV_ROOT!=zenv_pwd, source new .zenv and reset ZENV_ROOT
# TODO: Add verification for new zenv and updated zenv
chpwd() {
zenv_pwd="$(zenv_locate_root)"
zenv_eval_interface
interface=$?
if [ "$zenv_pwd" = "" ] && [ "$ZENV_ROOT" != "" ] ; then
echo "exit env"
if [ $interface -eq 0 ] ; then
echo "Downing environment"
zenv_down
unfunction zenv_down
unfunction zenv_up
fi
unset ZENV_ROOT
return
fi
if [ "$zenv_pwd" != "" ] ; then
if [ "$ZENV_ROOT" = "" ] ; then
export ZENV_ROOT="$zenv_pwd"
source "$zenv_pwd/.zenv"
zenv_eval_interface
interface=$?
if [ $interface -eq 0 ] ; then
echo "Upping environment"
zenv_up
fi
fi
fi
}
zenv_eval_interface() {
which zenv_up 1>/dev/null 2>&1
up=$?
which zenv_down 1>/dev/null 2>&1
down=$?
if [ $up -eq 0 ] && [ $down -eq 0 ] ; then
return 0
fi
return 1
}
zenv_locate_root() {
zenv_root=$(pwd -P 2>/dev/null || command pwd)
while [ ! -e "$zenv_root/.zenv" ] ; do
zenv_root=${zenv_root%/*}
if [ "$zenv_root" = "" ] ; then break; fi
done
echo "$zenv_root"
}