-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.zsh
61 lines (46 loc) · 1.11 KB
/
lib.zsh
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
function __pe_strip_original_path() {
local new_path=${PATH##"$PATH_ETHIC_HEAD"}
new_path=${new_path%%"$PATH_ETHIC_TAIL"}
echo $(__pe_normalize_path $new_path)
}
function __pe_rebuild_path_with() {
if [[ "$1" == "" ]]; then
exit 1
fi
local new_path="$PATH_ETHIC_HEAD:$1:$PATH_ETHIC_TAIL"
echo $(__pe_normalize_path $new_path)
}
function __pe_reexport_path() {
local target_path=
if [[ "$1" == "" ]]; then
target_path=$(__pe_strip_original_path)
else
target_path="$1"
fi
export PATH=$(__pe_rebuild_path_with "$target_path")
}
function __pe_normalize_path() {
local elements=("${(s/:/)1}")
local out=
for e in "${elements[@]}"
do
if [[ "$out" == "" ]]; then
out="$e"
elif [[ "$e" != "" ]]; then
out="$out:$e"
fi
done
echo $out
}
function __pe_log_error() {
__pe_log "$fg[red]ERROR:$reset_color $1"
}
function __pe_log_warning() {
__pe_log "$fg[yellow]WARNING:$reset_color $1"
}
function __pe_log() {
print "$1" >&2
}
function __pe_is_directory() {
[ -d "$1" ]
}