forked from zsh-users/antigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel.zsh
85 lines (74 loc) · 2.78 KB
/
parallel.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Initialize parallel lib
-antigen-parallel-init () {
WARN "Init parallel extension" PARALLEL
typeset -ga _PARALLEL_BUNDLE=()
if -antigen-interactive-mode; then
return 1
fi
}
-antigen-parallel-execute() {
WARN "Exec parallel extension" PARALLEL
# Install bundles in parallel
antigen-bundle-parallel-execute () {
WARN "Parallel antigen-bundle-parallel-execute" PARALLEL
typeset -a pids; pids=()
local args pid
WARN "Gonna install in parallel ${#_PARALLEL_BUNDLE} bundles." PARALLEL
# Do ensure-repo in parallel
WARN "${_PARALLEL_BUNDLE}" PARALLEL
typeset -Ua repositories # Used to keep track of cloned repositories to avoid
# trying to clone it multiple times.
for args in ${_PARALLEL_BUNDLE}; do
typeset -A bundle; -antigen-parse-args 'bundle' ${=args}
if [[ ! -d ${bundle[dir]} && $repositories[(I)${bundle[url]}] == 0 ]]; then
WARN "Install in parallel ${bundle[name]}." PARALLEL
echo "Installing ${bundle[name]}!..."
# TODO what happens if we request multiple bundles on different branches
# on the same repository/library:
# antigen bundle example/bundle1@develop
# antigen bundle example/bundle2 (default master)
-antigen-ensure-repo "${bundle[url]}" > /dev/null &!
pids+=($!)
else
WARN "Bundle ${bundle[name]} already cloned locally." PARALLEL
fi
repositories+=(${bundle[url]})
done
# Wait for all background processes to end
while [[ $#pids > 0 ]]; do
for pid in $pids; do
if [[ $(ps -o pid= -p $pid) == "" ]]; then
pids[$pids[(I)$pid]]=()
fi
done
sleep .5
done
builtin local bundle &> /dev/null
for bundle in ${_PARALLEL_BUNDLE[@]}; do
antigen-bundle $bundle
done
WARN "Parallel install done" PARALLEL
}
# Hooks antigen-apply in order to release hooked functions
antigen-apply-parallel () {
WARN "Parallel pre-apply" PARALLEL PRE-APPLY
#antigen-remove-hook antigen-pre-apply-parallel
# Hooks antigen-bundle in order to parallel its execution.
antigen-bundle-parallel () {
TRACE "antigen-bundle-parallel: $@" PARALLEL
_PARALLEL_BUNDLE+=("${(j: :)${@}}")
}
antigen-add-hook antigen-bundle antigen-bundle-parallel replace
}
antigen-add-hook antigen-apply antigen-apply-parallel pre once
antigen-apply-parallel-execute () {
WARN "Parallel replace-apply" PARALLEL REPLACE-APPLY
antigen-remove-hook antigen-bundle-parallel
# Process all parallel bundles.
antigen-bundle-parallel-execute
unset _PARALLEL_BUNDLE
antigen-remove-hook antigen-apply-parallel-execute
antigen-apply
}
antigen-add-hook antigen-apply antigen-apply-parallel-execute replace once
}