-
Notifications
You must be signed in to change notification settings - Fork 0
/
→za-patch-dl-handler
111 lines (92 loc) · 3.36 KB
/
→za-patch-dl-handler
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
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
[[ "$1" = plugin ]] && \
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" || \
local type="$1" url="$2" id_as="$3" dir="$4"
# FUNCTION: .z-a-patch-dl-download-file-stdout {{{
# Downloads file to stdout. Supports following backend commands:
# curl, wget, lftp, lynx. Used by snippet loading.
.z-a-patch-dl-download-file-stdout() {
local url="$1" restart="$2"
setopt localoptions localtraps
if (( restart )); then
(( ${path[(I)/usr/local/bin]} )) || \
{
path+=( "/usr/local/bin" );
trap "path[-1]=()" EXIT
}
if (( ${+commands[curl]} )) then
command curl -fsSL "$url" || return 1
elif (( ${+commands[wget]} )); then
command wget -q "$url" -O - || return 1
elif (( ${+commands[lftp]} )); then
command lftp -c "cat $url" || return 1
elif (( ${+commands[lynx]} )) then
command lynx -source "$url" || return 1
else
return 2
fi
else
if type curl 2>/dev/null 1>&2; then
command curl -fsSL "$url" || return 1
elif type wget 2>/dev/null 1>&2; then
command wget -q "$url" -O - || return 1
elif type lftp 2>/dev/null 1>&2; then
command lftp -c "cat $url" || return 1
else
.z-a-patch-dl-download-file-stdout "$url" "1"
return $?
fi
fi
return 0
} # }}}
if [[ -n ${ZINIT_ICE[dl]} && ${ZINIT_ICE[dl]} != ink=[-/[:alnum:]]* ]] {
local -a dls srcdst
dls=( "${(s.;.)ZINIT_ICE[dl]}" )
local dl hd tl
for dl ( $dls ) {
srcdst=( ${(@s.->.)dl} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
hd="" tl=""
[[ -n ${srcdst[2]} ]] && {
@zinit-substitute 'srcdst[2]'
hd="${srcdst[2]:h}"
tl="${srcdst[2]:t}"
} || {
@zinit-substitute 'srcdst[1]'
hd="."
tl="${${srcdst[1]%%\?*}:t}"
}
local tdir="${${(M)hd:#/*}:-$dir/$hd}"
# Create the destination directory
command mkdir -p "$tdir"
local ret=0
.z-a-patch-dl-download-file-stdout "${srcdst[1]}" >! "$tdir/$tl" || {
.z-a-patch-dl-download-file-stdout "${srcdst[1]}" 1 >! "$tdir/$tl" || {
print -P -- "%F{38}patch-dl annex: %F{160}Couldn't download" \
"the url %F{220}${srcdst[1]}%f"
ret=1
}
}
(( !ret && !ICE_OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )) && \
print -P -- "%F{38}patch-dl annex: %F{154}File %F{220}$tl%F{154}" \
"downloaded correctly%f"
}
}
if [[ -n "${ZINIT_ICE[patch]}" ]] {
local -a patches
patches=( "${(s.;.)ZINIT_ICE[patch]}" )
patches=( "${patches[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
local pch
for pch ( $patches ) {
@zinit-substitute pch
(( !ICE_OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )) && \
print -P -- "%F{38}patch-dl annex: %F{154}Applying patch %F{220}$pch...%f"
( cd -q "$dir"
print -nP "%F{220}"
command patch -s -N -p1 -i "$pch"
print -nP "%f"
)
}
}
# vim:ft=zsh:sw=4:sts=4:et