-
Notifications
You must be signed in to change notification settings - Fork 2
/
penv
executable file
·86 lines (78 loc) · 2.7 KB
/
penv
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
#!/usr/bin/env zsh
zparseopts -D -- P+:=abs_paths p+:=rel_paths f+:=env_files s+:=env_vars c+:=cmds || exit
for p in ${(@)abs_paths:#-P}; do
prefixes=($p $prefixes)
done
for p in ${(@)rel_paths:#-p}; do
for b in ${(s.:.)PENVPATH}; do
if [[ -e "$b/$p" ]] then
prefixes=("$b/$p" $prefixes)
break
fi
done
done
bin_path=("$PATH")
library_path=("$LD_LIBRARY_PATH")
include_path=("$CPPFLAGS")
linker_path=("$LDFLAGS")
man_path=("$MANPATH")
for p in ${(@)prefixes}; do
[[ -e "$p/bin" ]] && bin_path=("$p/bin" $bin_path)
[[ -e "$p/sbin" ]] && bin_path=("$p/sbin" $bin_path)
[[ -e "$p/include" ]] && include_path=("-I$p/include" $include_path)
[[ -e "$p/share/man" ]] && man_path=("$p/share/man" $man_path)
[[ -e "$p/lib" ]] && library_path=("$p/lib" $library_path)
[[ -e "$p/lib" ]] && linker_path=("-L$p/lib" $linker_path)
[[ -e "$p/lib" ]] && cflags=("-Wl,-rpath=$p/lib" $cflags)
done
for f in ${(@)env_files:#-f}; do
source $f
done
for s in ${(@)env_vars:#-s}; do
var=("$(env \
PATH="${(j.:.)bin_path}" \
LD_LIBRARY_PATH="${(j.:.)library_path}" \
LD_RUN_PATH="${(j.:.)library_path}" \
CPPFLAGS="${(j. .)include_path}" \
LDFLAGS="${(j. .)linker_path}" \
MAN_PATH="${(j.:.)man_path}" \
CFLAGS="${(j.:.)cflags}" \
${(@)vars} \
envsubst <<< $s)")
vars=($vars "$(env \
PATH="${(j.:.)bin_path}" \
LD_LIBRARY_PATH="${(j.:.)library_path}" \
LD_RUN_PATH="${(j.:.)library_path}" \
CPPFLAGS="${(j. .)include_path}" \
LDFLAGS="${(j. .)linker_path}" \
MAN_PATH="${(j.:.)man_path}" \
CFLAGS="${(j.:.)cflags}" \
${(@)vars} \
zsh -c "eval echo $s")")
done
for c in ${(@)cmds:#-c}; do
env \
PREFIXES="${(j.:.)prefixes}" \
PATH="${(j.:.)bin_path}" \
LD_LIBRARY_PATH="${(j.:.)library_path}" \
LD_RUN_PATH="${(j.:.)library_path}" \
CPPFLAGS="${(j. .)include_path}" \
LDFLAGS="${(j. .)linker_path}" \
MAN_PATH="${(j.:.)man_path}" \
CFLAGS="${(j.:.)cflags}" \
${(@)vars} \
$SHELL -c "$c"
done
if [[ -z "$cmds" ]]; then
exec env \
PREFIXES="${(j.:.)prefixes}" \
PATH="${(j.:.)bin_path}" \
LD_LIBRARY_PATH="${(j.:.)library_path}" \
LD_RUN_PATH="${(j.:.)library_path}" \
CPPFLAGS="${(j. .)include_path}" \
LDFLAGS="${(j. .)linker_path}" \
MAN_PATH="${(j.:.)man_path}" \
CFLAGS="${(j.:.)cflags}" \
${(@)vars} \
"$@"
fi