mirror of
https://github.com/zdharma-continuum/zinit-annex-patch-dl.git
synced 2026-09-10 07:26:19 -04:00
fix: consistent logging format (#14)
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
parent
8542a149c6
commit
7386010554
|
|
@ -14,15 +14,15 @@ za-patch-dl-help-null-handler() { :; }
|
|||
|
||||
# Register !atclone hook
|
||||
@zinit-register-annex "zinit-annex-patch-dl" \
|
||||
hook:\!atclone-20 \
|
||||
za-patch-dl-handler \
|
||||
za-patch-dl-help-null-handler \
|
||||
"dl''|patch''"
|
||||
hook:\!atclone-20 \
|
||||
za-patch-dl-handler \
|
||||
za-patch-dl-help-null-handler \
|
||||
"dl''|patch''"
|
||||
|
||||
# Register !atpull hook
|
||||
@zinit-register-annex "zinit-annex-patch-dl" \
|
||||
hook:atpull-20 \
|
||||
za-patch-dl-handler \
|
||||
za-patch-dl-help-null-handler
|
||||
hook:atpull-20 \
|
||||
za-patch-dl-handler \
|
||||
za-patch-dl-help-null-handler
|
||||
|
||||
# vim:ft=zsh:sw=2:sts=2:et
|
||||
|
|
|
|||
|
|
@ -2,112 +2,112 @@ emulate -RL zsh
|
|||
setopt extendedglob noshortloops typesetsilent warncreateglobal
|
||||
|
||||
if [[ "$1" = plugin ]]; then
|
||||
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5"
|
||||
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5"
|
||||
else
|
||||
local type="$1" url="$2" id_as="$3" dir="$4"
|
||||
local type="$1" url="$2" id_as="$3" dir="$4"
|
||||
fi
|
||||
|
||||
# FUNCTION: .zinit-annex-patch-dl-download-file-stdout {{{
|
||||
# Downloads file to stdout. Used by snippet loading.
|
||||
# Supports following backend commands: curl, wget, lftp, lynx.
|
||||
.zinit-annex-patch-dl-download-file-stdout() {
|
||||
local url="$1" restart="$2"
|
||||
local url="$1" restart="$2"
|
||||
|
||||
setopt localoptions localtraps
|
||||
setopt localoptions localtraps
|
||||
|
||||
if (( restart )); then
|
||||
if (( !${path[(I)/usr/local/bin]} )); then
|
||||
path+=( "/usr/local/bin" );
|
||||
trap "path[-1]=()" EXIT
|
||||
fi
|
||||
if (( restart )); then
|
||||
if (( !${path[(I)/usr/local/bin]} )); then
|
||||
path+=( "/usr/local/bin" );
|
||||
trap "path[-1]=()" EXIT
|
||||
fi
|
||||
|
||||
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
|
||||
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
|
||||
return 2
|
||||
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
|
||||
.zinit-annex-patch-dl-download-file-stdout "$url" "1"
|
||||
return $?
|
||||
fi
|
||||
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
|
||||
.zinit-annex-patch-dl-download-file-stdout "$url" "1"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
return 0
|
||||
} # }}}
|
||||
|
||||
if [[ -n ${ICE[dl]} && ${ICE[dl]} != ink=[-/[:alnum:]]* ]]; then
|
||||
local -a dls srcdst
|
||||
dls=( "${(s.;.)ICE[dl]}" )
|
||||
local -a dls srcdst
|
||||
dls=( "${(s.;.)ICE[dl]}" )
|
||||
|
||||
local dl hd tl
|
||||
for dl ( $dls ) {
|
||||
srcdst=( ${(@s.->.)dl} )
|
||||
srcdst=( ${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/} )
|
||||
hd="" tl=""
|
||||
local dl hd tl
|
||||
for dl ( $dls ); do
|
||||
srcdst=( ${(@s.->.)dl} )
|
||||
srcdst=( ${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/} )
|
||||
hd="" tl=""
|
||||
|
||||
if [[ -n ${srcdst[2]} ]]; then
|
||||
@zinit-substitute 'srcdst[2]'
|
||||
hd="${srcdst[2]:h}"
|
||||
tl="${srcdst[2]:t}"
|
||||
else
|
||||
@zinit-substitute 'srcdst[1]'
|
||||
hd="."
|
||||
tl="${${srcdst[1]%%\?*}:t}"
|
||||
fi
|
||||
if [[ -n ${srcdst[2]} ]]; then
|
||||
@zinit-substitute 'srcdst[2]'
|
||||
hd="${srcdst[2]:h}"
|
||||
tl="${srcdst[2]:t}"
|
||||
else
|
||||
@zinit-substitute 'srcdst[1]'
|
||||
hd="."
|
||||
tl="${${srcdst[1]%%\?*}:t}"
|
||||
fi
|
||||
|
||||
local tdir="${${(M)hd:#/*}:-$dir/$hd}"
|
||||
local tdir="${${(M)hd:#/*}:-$dir/$hd}"
|
||||
|
||||
# Create the destination directory
|
||||
command mkdir -p "$tdir"
|
||||
# Create the destination directory
|
||||
command mkdir -p "$tdir"
|
||||
|
||||
local ret=0
|
||||
local ret=0
|
||||
|
||||
if ! .zinit-annex-patch-dl-download-file-stdout "${srcdst[1]}" >! "$tdir/$tl"; then
|
||||
if ! .zinit-annex-patch-dl-download-file-stdout "${srcdst[1]}" 1 >! "$tdir/$tl"; then
|
||||
+zinit-message "{info}[{pre}patch-dl annex{info}]{error} Failed to download the URL {glob}${srcdst[1]}{rst}"
|
||||
ret=1
|
||||
fi
|
||||
fi
|
||||
if ! .zinit-annex-patch-dl-download-file-stdout "${srcdst[1]}" >! "$tdir/$tl"; then
|
||||
if ! .zinit-annex-patch-dl-download-file-stdout "${srcdst[1]}" 1 >! "$tdir/$tl"; then
|
||||
+zinit-message "{e} patch-dl-annex: Failed to download the URL {glob}${srcdst[1]}{rst}"
|
||||
ret=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( !ret && !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
+zinit-message "{info}[{pre}patch-dl annex{info}] {file}${tl}{rst} downloaded successfully"
|
||||
fi
|
||||
}
|
||||
if (( !ret && !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
+zinit-message "{m} patch-dl-annex: {file}$tl{rst} downloaded successfully"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -n "${ICE[patch]}" ]]; then
|
||||
local -a patches
|
||||
patches=( "${(s.;.)ICE[patch]}" )
|
||||
patches=( "${patches[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
|
||||
local -a patches
|
||||
patches=( "${(s.;.)ICE[patch]}" )
|
||||
patches=( "${patches[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
|
||||
|
||||
local pch
|
||||
for pch ( $patches ) {
|
||||
@zinit-substitute pch
|
||||
local pch
|
||||
for pch ( $patches ) {
|
||||
@zinit-substitute pch
|
||||
|
||||
if (( !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
+zinit-message "{info}[{pre}patch-dl annex{info}]{rst} Applying patch {pname}${pch}{rst}"
|
||||
fi
|
||||
if (( !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
+zinit-message "{m} patch-dl-annex: Applying patch {pname}$pch{rst}"
|
||||
fi
|
||||
|
||||
(
|
||||
cd -q "$dir"
|
||||
print -nP "%F{220}"
|
||||
command patch -s -N -p1 -i "$pch"
|
||||
print -nP "%f"
|
||||
)
|
||||
}
|
||||
(
|
||||
builtin cd -q "$dir"
|
||||
builtin print -nP -- "%F{220}"
|
||||
command patch -s -N -p1 -i "$pch"
|
||||
builtin print -nP -- "%f"
|
||||
)
|
||||
}
|
||||
fi
|
||||
|
||||
# vim:ft=zsh:sw=2:sts=2:et
|
||||
|
|
|
|||
Loading…
Reference in a new issue