mirror of
https://github.com/zdharma-continuum/zinit-annex-patch-dl.git
synced 2026-09-10 07:26:19 -04:00
style: format zsh and markdown to zinit convention (#3)
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
parent
f4cbf42374
commit
ddde9c8bbc
44
README.md
44
README.md
|
|
@ -1,9 +1,6 @@
|
|||
# zinit-annex-patch-dl
|
||||
|
||||
## Introduction
|
||||
|
||||
A Zsh-Zinit extension (i.e. an
|
||||
[annex](https://zdharma-continuum.github.io/zinit/wiki/Annexes/)) that downloads files and
|
||||
A Zinit extension (i.e., an [annex](https://zdharma-continuum.github.io/zinit/wiki/Annexes/)) that downloads files and
|
||||
applies patches. It adds two ice modifiers:
|
||||
|
||||
```zsh
|
||||
|
|
@ -16,43 +13,42 @@ and
|
|||
zinit ice patch'{file-name-with-the-patch-to-apply}; …' …
|
||||
```
|
||||
|
||||
The Zinit annex (i.e. an extension) will:
|
||||
The Zinit annex (i.e., an extension) will:
|
||||
|
||||
- download the given `{URL}` under the path `{optional-output-file-name}` (if no
|
||||
file name given, then it is taken from last segment of the URL) in case of the
|
||||
`dl''` ice-mod,
|
||||
- apply a patch given by the `{file-name-with-the-patch-to-apply}` in case of
|
||||
the `patch''` ice-mod.
|
||||
- Download the given `{URL}` under the path `{optional-output-file-name}` (if no file name is given, then it is taken
|
||||
from the last segment of the URL) in case of the `dl''` ice-mod,
|
||||
- Apply a patch given by the `{file-name-with-the-patch-to-apply}` in case of the `patch''` ice-mod.
|
||||
|
||||
You can use this functionality to download and apply patches. For example, to
|
||||
install `fbterm`, two patches are being needed, one to fix the operation, the
|
||||
other one to fix the build:
|
||||
You can use this functionality to download and apply patches. For example, to install `fbterm`, two patches are being
|
||||
needed, one to fix the operation, the other one to fix the build:
|
||||
|
||||
```zsn
|
||||
```zsh
|
||||
zinit ice \
|
||||
as"command" pick"$ZPFX/bin/fbterm" \
|
||||
dl"https://bugs.archlinux.org/task/46860?getfile=13513 -> ins.patch" \
|
||||
dl"https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-build-with-gcc-6.patch?h=fbterm-git" \
|
||||
patch"ins.patch; 0001-Fix-build-with-gcc-6.patch" \
|
||||
as"command" \
|
||||
atclone"./configure --prefix=$ZPFX" \
|
||||
atpull"%atclone" \
|
||||
make"install" reset
|
||||
dl"https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-build-with-gcc-6.patch?h=fbterm-git" \
|
||||
dl"https://bugs.archlinux.org/task/46860?getfile=13513 -> ins.patch" \
|
||||
make"install" \
|
||||
patch"ins.patch; 0001-Fix-build-with-gcc-6.patch" \
|
||||
pick"$ZPFX/bin/fbterm" \
|
||||
reset
|
||||
|
||||
zinit load izmntuk/fbterm
|
||||
```
|
||||
|
||||
This command will result in:
|
||||
|
||||

|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
Simply load like a plugin, i.e. the following will add the annex to Zinit:
|
||||
Run the following command to add the annex to Zinit:
|
||||
|
||||
```zsh
|
||||
zinit light zdharma-continuum/zinit-annex-patch-dl
|
||||
```
|
||||
|
||||
After executing this command you can then use the `dl''` and `patch''` ice-mods.
|
||||
After executing this command, you can use the `dl''` and `patch''` ice-mods.
|
||||
|
||||
<!-- vim:set ft=markdown tw=80 et sw=4 sts=4: -->
|
||||
<!-- vim:set ft=markdown tw=120 et sw=4 sts=4: -->
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# According to the Zsh Plugin Standard:
|
||||
# In accordance with the Zsh Plugin Standard
|
||||
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
|
||||
|
||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||
|
|
@ -19,3 +19,5 @@ za-patch-dl-help-null-handler() { :; }
|
|||
@zinit-register-annex "zinit-annex-patch-dl" hook:\!atpull-20 \
|
||||
za-patch-dl-handler \
|
||||
za-patch-dl-help-null-handler
|
||||
|
||||
# vim:ft=zsh:sw=2:sts=2:et
|
||||
|
|
|
|||
|
|
@ -1,24 +1,25 @@
|
|||
emulate -RL zsh
|
||||
setopt extendedglob warncreateglobal typesetsilent noshortloops
|
||||
setopt extendedglob noshortloops typesetsilent warncreateglobal
|
||||
|
||||
[[ "$1" = plugin ]] && \
|
||||
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" || \
|
||||
if [[ "$1" = plugin ]]; then
|
||||
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5"
|
||||
else
|
||||
local type="$1" url="$2" id_as="$3" dir="$4"
|
||||
fi
|
||||
|
||||
# FUNCTION: .zinit-annex-patch-dl-download-file-stdout {{{
|
||||
# Downloads file to stdout. Supports following backend commands:
|
||||
# curl, wget, lftp, lynx. Used by snippet loading.
|
||||
# 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"
|
||||
|
||||
setopt localoptions localtraps
|
||||
|
||||
if (( restart )); then
|
||||
(( ${path[(I)/usr/local/bin]} )) || \
|
||||
{
|
||||
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
|
||||
|
|
@ -47,25 +48,25 @@ setopt extendedglob warncreateglobal typesetsilent noshortloops
|
|||
return 0
|
||||
} # }}}
|
||||
|
||||
if [[ -n ${ICE[dl]} && ${ICE[dl]} != ink=[-/[:alnum:]]* ]] {
|
||||
if [[ -n ${ICE[dl]} && ${ICE[dl]} != ink=[-/[:alnum:]]* ]]; then
|
||||
local -a dls srcdst
|
||||
dls=( "${(s.;.)ICE[dl]}" )
|
||||
|
||||
local dl hd tl
|
||||
for dl ( $dls ) {
|
||||
srcdst=( ${(@s.->.)dl} )
|
||||
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
|
||||
|
||||
srcdst=( ${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/} )
|
||||
hd="" tl=""
|
||||
[[ -n ${srcdst[2]} ]] && {
|
||||
|
||||
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}"
|
||||
|
||||
|
|
@ -74,21 +75,20 @@ if [[ -n ${ICE[dl]} && ${ICE[dl]} != ink=[-/[:alnum:]]* ]] {
|
|||
|
||||
local ret=0
|
||||
|
||||
.zinit-annex-patch-dl-download-file-stdout "${srcdst[1]}" >! "$tdir/$tl" || {
|
||||
.zinit-annex-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"
|
||||
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
|
||||
print -P -- "%F{38}[patch-dl annex]: %F{160}Failed to download the URL %F{220}${srcdst[1]}%f"
|
||||
ret=1
|
||||
}
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
(( !ret && !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 (( !ret && !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
print -P -- "%F{38}[patch-dl annex]: %F{154}File %F{220}$tl%F{154} downloaded correctly%f"
|
||||
fi
|
||||
}
|
||||
}
|
||||
fi
|
||||
|
||||
if [[ -n "${ICE[patch]}" ]] {
|
||||
if [[ -n "${ICE[patch]}" ]]; then
|
||||
local -a patches
|
||||
patches=( "${(s.;.)ICE[patch]}" )
|
||||
patches=( "${patches[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
|
||||
|
|
@ -97,15 +97,17 @@ if [[ -n "${ICE[patch]}" ]] {
|
|||
for pch ( $patches ) {
|
||||
@zinit-substitute pch
|
||||
|
||||
(( !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"
|
||||
if (( !OPTS[opt_-q,--quiet] && ZINIT[annex-multi-flag:pull-active] == 2 )); then
|
||||
print -P -- "%F{38}[patch-dl annex]: %F{154}Applying patch %F{220}$pch...%f"
|
||||
fi
|
||||
|
||||
( cd -q "$dir"
|
||||
(
|
||||
cd -q "$dir"
|
||||
print -nP "%F{220}"
|
||||
command patch -s -N -p1 -i "$pch"
|
||||
print -nP "%f"
|
||||
)
|
||||
}
|
||||
}
|
||||
fi
|
||||
|
||||
# vim:ft=zsh:sw=4:sts=4:et
|
||||
# vim:ft=zsh:sw=2:sts=2:et
|
||||
|
|
|
|||
Loading…
Reference in a new issue