diff --git a/README.md b/README.md
index 59a03e1..569455b 100644
--- a/README.md
+++ b/README.md
@@ -1,152 +1,147 @@
-# zinit-annex-readurl
+# zinit-annex-readurl
-
+
-
+- [zinit-annex-readurl](#zinit-annex-readurl)
+ - [Skipping `dlink''` Ice](#skipping-dlink-ice)
+ - [Summary](#summary)
+ - [Sorting The Matched URLs / Package Versions](#sorting-the-matched-urls--package-versions)
+ - [Filtering The Matched URLs](#filtering-the-matched-urls)
+ - [Other Examples](#other-examples)
-**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
-- [Introduction](#introduction)
-- [Intermediate Download Page](#intermediate-download-page)
-- [Skipping `dlink''` Ice](#skipping-dlink-ice)
-- [Summary](#summary)
-- [Installation](#installation)
-- [Other Examples](#other-examples)
-- [Sorting The Matched URLs / Package Versions](#sorting-the-matched-urls--package-versions)
-- [Filtering The Matched URLs](#filtering-the-matched-urls)
+This Zinit extension allows to automatically download the newest version of a file to which the URL
+is hosted on a webpage.
-
+It works as follows:
-## Introduction
+- invoke `snippet` (or pass the `http://…` address using the `for` syntax) on the web-page that
+ hosts the URL to the file to download,
+- provide `dlink''` ice with the expected file-download URL, replacing the version with the
+ `%VERSION%` keyword,
+- also, provide `as''` ice with one of the following values: `readurl`, `readurl|command`,
+ `readurl|completion`, `readurl|null`; the part after the `|` has the same meaning as in the normal
+ `as''` ice.
-This Zinit extension allows to automatically download the newest version of
-a file to which URL is hosted on a webpage.
+So, for example:
-It works as follows:
+````zsh
+zinit for \
+ as'readurl|command' \
+ dlink'/junegunn/fzf-bin/releases/download/%VERSION%/fzf-%VERSION%-linux_amd64.tgz'
+ extract \
+ id-as'fzf'
+ https://github.com/junegunn/fzf-bin/releases/
+```
+The snippet is just an example. The same effect is obtained by loading as `junegunn/fzf-bin` plugin
+with `from'gh-r'` ice.
-- invoke `snippet` (or simply pass the `http://…` address using the `for`
- syntax) on the web-page that hosts the URL to the file to download,
-- provide `dlink''` ice with the expected file-download URL replacing the version
- with the `%VERSION%` keyword,
-- also provide `as''` ice with one of the following values: `readurl`,
- `readurl|command`, `readurl|completion`, `readurl|null`; the part after the `|` has
- the same meaning as in the normal `as''` ice.
+As demonstrated, the `dlink''` can be a relative or an absolute path and also a full URL (i.e.:
+beginning with the `http://…` prefix).
-So, for example:
+
+## Installation
+
+Load as a regular plugin via:
```zsh
-zinit id-as=fzf as='readurl|command' extract \
- dlink='/junegunn/fzf-bin/releases/download/%VERSION%/fzf-%VERSION%-linux_amd64.tgz' \
- for https://github.com/junegunn/fzf-bin/releases/
+zinit light zdharma-continuum/z-a-readurl
```
-The snippet is just an example. The same effect is obtained by loading as
-`junegunn/fzf-bin` plugin with `from'gh-r'` ice.
-
-As it can be seen, the `dlink''` can be a relative or an absolute path and also
-a full URL (i.e.: beginning with the `http://…` prefix).
+After executing the above command (possibly via `zshrc`), it's then possible to use the `dlink''` and
+`dlink0''` ices and the special `as'readurl|…'` value of the `as''` ice.
## Intermediate Download Page
-Sometimes, like it is in case of
-[terraform](http://releases.hashicorp.com/terraform) command, the final download
-link isn't at the download page, but on a page that's listed on it. In such case
-use the `dlink0''` ice to provide the pattern for the additional, intermediate
-download page. For example, in case of `terraform`, the Zinit command is:
+Sometimes, like in the case of the [terraform](http://releases.hashicorp.com/terraform) command, the download link isn't on the download page but on a page listed on it. In such cases utilize
+the `dlink0''` ice and provide the pattern for the additional, intermediate download page. For
+For example, in the case of `terraform`, the Zinit command is:
```zsh
-zinit id-as=terraform as='readurl|command' extract \
- dlink0='/terraform/%VERSION%/' \
- dlink='/terraform/%VERSION%/terraform_%VERSION%_linux_386.zip' \
- for \
- http://releases.hashicorp.com/terraform/
-```
+zinit for \
+ as'readurl|command' \
+ dlink0'/terraform/%VERSION%/' \
+ dlink'/terraform/%VERSION%/terraform_%VERSION%_linux_386.zip' \
+ extract \
+ id-as'terraform' \
+ http://releases.hashicorp.com/terraform/
+````
-## Skipping `dlink''` Ice
+## Skipping `dlink''` Ice
-Sometimes the URL of the download page differs from the URL of the archive in
-just a few `/`-sections. In such case, it is possible to skip the `dlink''` ice
-by appending a `++`-separated fragment of the archive URL, like so:
+Sometimes the URL of the download page differs from the URL of the archive in just a few
+`/`-sections. In such a case, it is possible to skip the `dlink''` ice by appending a `++`-separated
+fragment of the archive URL, like so:
```zsh
-zinit as'readurl|command' extract for \
- http://domain.com/download-page++/archive.zip
+zinit for \
+ as'readurl|command' \
+ extract \
+ http://domain.com/download-page++/archive.zip
```
-If the archive URL has some different `/`-sections, then it's possible to strip
-the conflicting ones from the download URL by using `+++`, `++++`, etc. – the
-number of the `/`-section that'll be stripped equals to the number of the `+`
-minus
-2\. So, for example:
+If the archive URL has some different `/`-sections, then it's possible to strip the conflicting ones
+from the download URL by using `+++`, `++++`, etc. – the number of the `/`-section that'll be
+stripped equals the number of the `+` minus 2. So, for example:
```zsh
-zinit as'readurl|command' extract for \
- http://domain.com/download-page/removed-section+++/archive.zip
+zinit for \
+ as'readurl|command' \
+ extract \
+ http://domain.com/download-page/removed-section+++/archive.zip
```
-## Summary
+## Summary
The annex provides:
1. Two new ices: `dlink''` and `dlink0''`.
-1. A handling of the special values of the `as''` ice, i.e.: of `as'readurl'`,
+2. A handling of the special values of the `as''` ice, i.e.: of `as'readurl'`,
`as'readurl|command'`, etc.
The annex works only with snippets, not plugins.
-## Installation
-
-Simply load like a regular plugin, i.e.:
+## Sorting The Matched URLs / Package Versions
-```zsh
-zinit light zdharma-continuum/z-a-readurl
-```
+Sometimes the download page doesn't list the package versions from newest to the oldest, but in some
+other order. In such case, it's possible to sort the URLs / package versions by prepending the
+chosen `dlink` ice (`dlink0''` or `dlink''`) with the exclamation mark (`dlink'!…'`, etc.). See the
+next section for an example:
-After executing the above command (possibly via `zshrc`) it's then possible to
-use the `dlink''` and `dlink0''` ices and also the special `as'readurl|…'` value
-of the `as''` ice.
+## Filtering The Matched URLs
-## Sorting The Matched URLs / Package Versions
-
-Sometimes the download page doesn't list the package versions from newest to the
-oldest, but in some other order. In such case it's possible to sort the URLs
-/ package versions by prepending the chosen `dlink` ice (`dlink0''` or
-`dlink''`) with the exclamation mark (`dlink'!…'`, etc.). See the next section
-for an example:
-
-## Filtering The Matched URLs
-
-Sometimes there are some unwanted URLs that match the `dlink''`/`dlink0''`
-regex / pattern. In such case it's possible to filter them out by appending
-a filtering regex to the `dlink''` ice as:
-`dlink='the-main-regex~%the-unwanted-URLs-regex%'` (or the same for `dlink0''`).
-An example package that can benefit from this is the [Open
-Shift](https://www.openshift.com/) client, which doesn't sort the URLs from
-latest to the oldest – hence the exclamation mark (`!`) prepend – and it has
-special URLs like `stable-4.4` or `candidate-4.5` together with the regular
-version URLs (like `4.5.0-rc.1`):
+Sometimes some unwanted URLs match the `dlink''`/`dlink0''` regex/pattern. In such case it's
+possible to filter them out by appending a filtering regex to the `dlink''` ice as:
+`dlink='the-main-regex~%the-unwanted-URLs-regex%'` (or the same for `dlink0''`). An example package
+that can benefit from this is the [Open Shift](https://www.openshift.com/) client, which doesn't
+sort the URLs from latest to the oldest – hence the exclamation mark (`!`) prepend – and it has
+special URLs like `stable-4.4` or `candidate-4.5` together with the regular version URLs (like
+`4.5.0-rc.1`):
```zsh
-zinit id-as"ocp" as"readurl|command" \
+zinit for \
+ as'readurl|command' \
+ dlink'openshift-client-windows-%VERSION%.zip' \
dlink0'!%VERSION%~%(stable|latest|fast|candidate).*%' \
- dlink"openshift-client-windows-%VERSION%.zip" for \
- https://mirror.openshift.com/pub/openshift-v4/clients/ocp/
+ id-as'ocp' \
+ https://mirror.openshift.com/pub/openshift-v4/clients/ocp/
```
-The above snippet of Zsh code / Zinit invocation will sort the URLs
-(`dlink0'!…'`) and then filter out the special ones from the results (via
-`…~%(stable|latest|fast|candidate).*%`), this way selecting the latest version
-of the Open Shift client.
+The above snippet of Zsh code / Zinit invocation will sort the URLs (`dlink0'!…'`) and then filter
+out the special ones from the results (via `…~%(stable|latest|fast|candidate).*%`), this way
+selecting the latest version of the Open Shift client.
-## Other Examples
+## Other Examples
[**Pulumi**](https://www.pulumi.com/), a tool to create, deploy, and manage modern cloud software.
```zsh
-zi id-as'pulumi' as'readurl|null' extract'!' \
- dlink='https://get.pulumi.com/releases/sdk/pulumi-%VERSION%-linux-x64.tar.gz' \
- sbin'pulumi*' for \
- https://www.pulumi.com/docs/get-started/install/versions/
+zi for \
+ as'readurl|null' \
+ dlink'https://get.pulumi.com/releases/sdk/pulumi-%VERSION%-linux-x64.tar.gz' \
+ extract'!' \
+ id-as'pulumi' \
+ sbin'pulumi*' \
+ https://www.pulumi.com/docs/get-started/install/versions/
```
-
-
diff --git a/z-a-readurl.plugin.zsh b/z-a-readurl.plugin.zsh
index c8cd54c..62dd78c 100644
--- a/z-a-readurl.plugin.zsh
+++ b/z-a-readurl.plugin.zsh
@@ -1,11 +1,11 @@
-# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-
-# Copyright (c) 2019-2020 Sebastian Gniazdowski
-# License MIT
+#!/usr/bin/env zsh
+# -*- mode: sh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
+#
+# Copyright (c) 2016-2020 Sebastian Gniazdowski and contributors
+# Copyright (c) 2021-2022 zdharma-continuum and contributors
# According to the Zsh Plugin Standard:
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
-
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
@@ -14,11 +14,13 @@ autoload -Uz za-readurl-preinit-handler
# An empty stub to fill the help handler fields
→za-readurl-help-null-handler() { :; }
-@zinit-register-annex "zinit-annex-readurl" \
- hook:preinit-10 \
- za-readurl-preinit-handler \
- →za-readurl-help-null-handler \
- "dlink''|.readurl''" # The ice conflict with dl'' from zinit-annex-patch-dl is being handled
- # in the other annex
+# The ice conflict with dl'' from zinit-annex-patch-dl is being handled in the
+# other annex
+@zinit-register-annex \
+ "zinit-annex-readurl" \
+ hook:preinit-10 \
+ za-readurl-preinit-handler \
+ →za-readurl-help-null-handler \
+ "dlink''|.readurl''"
-# vim:ft=zsh:tw=80:sw=4:sts=4:et
+# vim:ft=zsh:sw=2:sts=2:et:foldmarker=[[[,]]]:foldmethod=marker
diff --git a/za-readurl-preinit-handler b/za-readurl-preinit-handler
index a84a647..5e77690 100755
--- a/za-readurl-preinit-handler
+++ b/za-readurl-preinit-handler
@@ -1,226 +1,218 @@
+
#!/usr/bin/env zsh
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-
-# Copyright (c) 2019-2020 Sebastian Gniazdowski
-# License MIT
+#
+# Copyright (c) 2016-2020 Sebastian Gniazdowski and contributors
+# Copyright (c) 2021-2022 zdharma-continuum and contributors
za-readurl-preinit-handler() {
-# Set the base and typically useful options
-builtin emulate -LR zsh
-builtin setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
+ # Set the base and typically useful options
+ builtin emulate -LR zsh
+ builtin setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
-if [[ $ICE[as] != (readurl*|*readurl) && $ICE[.readurl] != (readurl*|*readurl) ]]
-then
+ if [[ $ICE[as] != (readurl*|*readurl) && $ICE[.readurl] != (readurl*|*readurl) ]]
+ then
return 0
-fi
+ fi
-[[ $1 = plugin ]] && {
+ [[ $1 = plugin ]] && {
+zinit-message "{pre}readurl annex: {error}ERROR: as'$ICE[as]'" \
- "ice can be used only with snippets.{rst}"
+ "ice can be used only with snippets.{rst}"
return 7
-}
+ }
-local __type=$1 __url=$2 __id_as=$3 __dir=$4 __hook=$5 __subtype=$6
+ local __type=$1 __url=$2 __id_as=$3 __dir=$4 __hook=$5 __subtype=$6
-ICE[.readurl]=${ICE[.readurl]:-$ICE[as]}
+ ICE[.readurl]=${ICE[.readurl]:-$ICE[as]}
-if [[ $ICE[as] = ((readurl\||)(command|program)|(command|program)(\|readurl|)) ]] {
+ if [[ $ICE[as] = ((readurl\||)(command|program)|(command|program)(\|readurl|)) ]]; then
ICE[as]=command
-} elif [[ $ICE[as] = ((readurl\||)completion|completion(\|readurl|)) ]] {
+ elif [[ $ICE[as] = ((readurl\||)completion|completion(\|readurl|)) ]]; then
ICE[as]=completion
-} elif [[ $ICE[as] = ((readurl\||)null|null(\|readurl|)) ]] {
+ elif [[ $ICE[as] = ((readurl\||)null|null(\|readurl|)) ]]; then
ICE[as]=null
ICE[pick]=${ICE[pick]:-/dev/null}
-} else {
+ else
if [[ $ICE[as] != readurl ]] {
- +zinit-message "{pre}readurl annex: {msg2}" \
- "Warning: Unrecognized as'readurl|{data2}...{msg2}' variant ({data2}$ICE[as]{msg2})." \
- "Falling back to {meta}as{hi}'{data}readurl{hi}'{msg2}.{rst}"
+ +zinit-message "{pre}readurl annex: {msg2} Warning: Unrecognized as'readurl|{data2}...{msg2}' variant ({data2}$ICE[as]{msg2}). Falling back to {meta}as{hi}'{data}readurl{hi}'{msg2}.{rst}"
}
unset 'ICE[as]'
-}
+ fi
-if [[ -d $__dir && $__subtype != update(|:*) ]] {
+ if [[ -d $__dir && $__subtype != update(|:*) ]] {
return 0
-}
+ }
-local -a match mbegin mend
-local MATCH
-integer MBEGIN MEND
+ local -a match mbegin mend
+ local MATCH
+ integer MBEGIN MEND
-(( $+functions[.zinit-setup-plugin-dir] )) || builtin source $ZINIT[BIN_DIR]/zinit-install.zsh
+ (( $+functions[.zinit-setup-plugin-dir] )) || builtin source $ZINIT[BIN_DIR]/zinit-install.zsh
-match=()
-local dlpage=${__url%(#b)([^+])++*}
-dlpage=$dlpage$match[1]
+ match=()
+ local dlpage=${__url%(#b)([^+])++*}
+ dlpage=$dlpage$match[1]
-if [[ $ICE[dl] == (*\;)(#c0,1)ink(0)(#c0,1)[=:](#c0,1)[-_/[:alnum:]]* ]] {
+ if [[ $ICE[dl] == (*\;)(#c0,1)ink(0)(#c0,1)[=:](#c0,1)[-_/[:alnum:]]* ]] {
ICE[dlink]=${(j.;.)${${(@M)${(@s.;.)ICE[dl]}:#ink([=:]|)*}##ink([=:]|)}}
ICE[dl]=${(j.;.)${(@s.;.)ICE[dl]}:#ink([=:]|)*}
[[ -z $ICE[dlink] ]] && unset 'ICE[dlink]'
[[ -z $ICE[dl] ]] && unset 'ICE[dl]'
-}
+ }
-if [[ -z $ICE[dlink] ]] {
+ if [[ -z $ICE[dlink] ]]; then
local plus=${(MS)__url%%[^+]++##} pattern_url=$dlpage
plus=${plus#?++}
while [[ -n $plus ]] {
- pattern_url=${pattern_url:h}
- plus=${plus%+}
+ pattern_url=${pattern_url:h}
+ plus=${plus%+}
}
local pattern_url=${pattern_url}/${__url##*++}
-} else {
+ else
local -a urls sorts filters
urls=( ${(s.;.)ICE[dlink]} )
- if (( ${#urls} == 2 )) {
- local pattern_url=${urls[@]:#0*} pattern_url0=${${(M)urls[@]:#0*}##0(:|=)(#c0,1)}
- if [[ $pattern_url == \!* ]] {
- sorts[2]=1
- pattern_url=${pattern_url#\!}
- }
- if [[ $pattern_url == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
- if [[ $pattern_url == (#b)(*)\~%([^%]##)%(*) ]] {
- pattern_url=$match[1]$match[3]
- filters[2]=$match[2]
- }
- }
- if [[ $pattern_url0 == \!* ]] {
- sorts[1]=1
- pattern_url0=${pattern_url0#\!}
- }
- if [[ $pattern_url0 == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
- if [[ $pattern_url0 == (#b)(*)\~%([^%]##)%(*) ]] {
- pattern_url0=$match[1]$match[3]
- filters[1]=$match[2]
- }
+ if (( ${#urls} == 2 )); then
+ local pattern_url=${urls[@]:#0*} pattern_url0=${${(M)urls[@]:#0*}##0(:|=)(#c0,1)}
+ if [[ $pattern_url == \!* ]] {
+ sorts[2]=1
+ pattern_url=${pattern_url#\!}
+ }
+ if [[ $pattern_url == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
+ if [[ $pattern_url == (#b)(*)\~%([^%]##)%(*) ]] {
+ pattern_url=$match[1]$match[3]
+ filters[2]=$match[2]
}
- } elif (( ${#urls} == 1 )) {
- local pattern_url=${urls[@]:#0*} pattern_url0=${${(M)urls[@]:#0*}##0(:|=)(#c0,1)}
- if [[ -n $pattern_url0 ]] {
- +zinit-message "{pre}readurl annex: {error}ERROR:{rst}" \
- "The {meta}dlink0''{rst} ice cannot be used alone," \
- "{meta}dlink''{rst} is always required."
- return 9
+ }
+ if [[ $pattern_url0 == \!* ]] {
+ sorts[1]=1
+ pattern_url0=${pattern_url0#\!}
+ }
+ if [[ $pattern_url0 == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
+ if [[ $pattern_url0 == (#b)(*)\~%([^%]##)%(*) ]] {
+ pattern_url0=$match[1]$match[3]
+ filters[1]=$match[2]
}
- if [[ $pattern_url == \!* ]] {
- sorts[1]=1
- pattern_url=${pattern_url#\!}
- }
- if [[ $pattern_url == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
- if [[ $pattern_url == (#b)(*)\~%([^%]##)%(*) ]] {
- pattern_url=$match[1]$match[3]
- filters[1]=$match[2]
- }
- }
- } elif (( ${#urls} > 2 )) {
- +zinit-message "{pre}readurl annex: {error}ERROR: {msg2}The ice {meta}dlink''{msg2}" \
- "has been used too many times: {meta}#{obj}${#urls}{msg2}, while it can be used at most" \
- "two times, as {meta2}dlink0''{msg2} and then {meta2}dlink''{msg2}, aborting.{rst}"
+ }
+ elif (( ${#urls} == 1 )); then
+ local pattern_url=${urls[@]:#0*} pattern_url0=${${(M)urls[@]:#0*}##0(:|=)(#c0,1)}
+ if [[ -n $pattern_url0 ]] {
+ +zinit-message "{pre}readurl annex: {error}ERROR:{rst} The {meta}dlink0''{rst} ice cannot be used alone, {meta}dlink''{rst} is always required."
return 9
- } else {
- local pattern_url=$ICE[dlink]
- }
-}
-
-
-local -A map
-map=( ".*" "*" ".+" "?##" "+" "##" "*" "#" )
-local -a filters
-filters=( "${filters[@]//(#b)(${(~kj.|.)map})/$map[$match[1]]}" )
-
-local tmpfile="$(mktemp)"
-
-pattern_url=${pattern_url//\%VERSION\%/[.,a-zA-Z0-9_-]+}
-local pattern_url0=${pattern_url0//\%VERSION\%/[.,a-zA-Z0-9_-]+}
-
-integer index
-local cur_paturl
-for cur_paturl ( $pattern_url0 $pattern_url ) {
+ }
+ if [[ $pattern_url == \!* ]] {
+ sorts[1]=1
+ pattern_url=${pattern_url#\!}
+ }
+ if [[ $pattern_url == *[^\\]([\\][\\])#\~%[^%]##%* ]] {
+ if [[ $pattern_url == (#b)(*)\~%([^%]##)%(*) ]] {
+ pattern_url=$match[1]$match[3]
+ filters[1]=$match[2]
+ }
+ }
+ elif (( ${#urls} > 2 )); then
+ +zinit-message "{pre}readurl annex: {error}ERROR: \
+ {msg2}The ice {meta}dlink''{msg2} has been used too many times: \
+ {meta}#{obj}${#urls}{msg2}, while it can be used at most two times, as {meta2}dlink0''{msg2} and then {meta2}dlink''{msg2}, aborting.{rst}"
+ return 9
+ else
+ local pattern_url=$ICE[dlink]
+ fi
+ fi
+
+
+ local -A map
+ map=( ".*" "*" ".+" "?##" "+" "##" "*" "#" )
+ local -a filters
+ filters=( "${filters[@]//(#b)(${(~kj.|.)map})/$map[$match[1]]}" )
+
+ local tmpfile="$(mktemp)"
+
+ pattern_url=${pattern_url//\%VERSION\%/[.,a-zA-Z0-9_-]+}
+ local pattern_url0=${pattern_url0//\%VERSION\%/[.,a-zA-Z0-9_-]+}
+
+ integer index
+ local cur_paturl
+ for cur_paturl ( $pattern_url0 $pattern_url ) {
index+=1
.zinit-download-file-stdout $dlpage >! $tmpfile || {
- .zinit-download-file-stdout $dlpage 1 >! $tmpfile || {
- +zinit-message "{pre}readurl annex: {error}ERROR: couldn't" \
- "fetch the download page ({url}${dlpage//\%/%%}{error}){rst}"
- return 9
- }
+ .zinit-download-file-stdout $dlpage 1 >! $tmpfile || {
+ +zinit-message "{pre}readurl annex: {error}ERROR: couldn't fetch the download page ({url}${dlpage//\%/%%}{error}){rst}"
+ return 9
+ }
}
local -a list
list=( ${(@f)"$(noglob command egrep -io "href=.?$cur_paturl" $tmpfile)"} )
if (( sorts[index] )) {
- list=( ${list[@]:#[^[:digit:]]##} )
- list=( ${(On)list[@]} )
+ list=( ${list[@]:#[^[:digit:]]##} )
+ list=( ${(On)list[@]} )
}
if [[ -n $filters[index] ]] {
- list=( ${list[@]:#href=(?|)$~filters[index]} )
+ list=( ${list[@]:#href=(?|)$~filters[index]} )
}
local selected=${list[1]#href=}
selected=${selected#[\"\']}
if [[ -z $selected ]] {
- +zinit-message "{pre}readurl annex: {error}ERROR:{rst}" \
- "couldn't match the URL${${(M)cur_paturl:#$pattern_url0}:+-0} at the download page" \
- "(which is {url}${dlpage//\%/%%}{rst}${${__id_as:#$__url}:+; the snippet is being identified as" \
-"{meta}${__id_as}{rst}}; was matching {data2}${cur_paturl}{rst})."
- return 9
+ +zinit-message "{pre}readurl annex: {error}ERROR:{rst}" \
+ "couldn't match the URL${${(M)cur_paturl:#$pattern_url0}:+-0} at the download page" \
+ "(which is {url}${dlpage//\%/%%}{rst}${${__id_as:#$__url}:+; the snippet is being identified as" \
+ "{meta}${__id_as}{rst}}; was matching {data2}${cur_paturl}{rst})."
+ return 9
}
if [[ $selected = /* ]] {
- local domain protocol
- if [[ $dlpage = (#b)(#i)((http(s|)|ftp(s|)|ssh|scp)://|)([^/]##)(*) ]] {
- protocol=$match[1] domain=$match[5]
- }
- if [[ -z $domain ]] {
- +zinit-message "{pre}readurl annex: {ehi}ERROR:{error} couldn't establish the domain name (unsupported" \
- "protocol? supported are: {data}http(s){error},{data}ftp(s){error},{data}ssh{error},{data}scp{error}).{rst}"
- return 9
- }
- local new_url=${protocol:-http://}$domain$selected
- } elif [[ $selected = (#i)(http(s|)|ftp(s|)|ssh|scp)://* ]] {
- local new_url=$selected
- } else {
- local -a exts
- exts=(
- xhtml htmls html htm php php3 php4 phtml
- pl asp aspx ece js jsp jspx jhtml cfm py
- rb rhtml shtml cgi
- )
- if [[ $dlpage = *.(${(~j:|:)exts}) ]] {
- local new_url=${dlpage:h}/$selected
- } else {
- local new_url=$dlpage/$selected
- }
- }
-
- # Assign in case there's dlink0 given (i.e.: that this
- # URL was the dlink0 URL)
+ local domain protocol
+ if [[ $dlpage = (#b)(#i)((http(s|)|ftp(s|)|ssh|scp)://|)([^/]##)(*) ]] {
+ protocol=$match[1] domain=$match[5]
+ }
+ if [[ -z $domain ]] {
+ +zinit-message "{pre}readurl annex: {ehi}ERROR:{error} couldn't establish the domain name (unsupported" \
+ "protocol? supported are: {data}http(s){error},{data}ftp(s){error},{data}ssh{error},{data}scp{error}).{rst}"
+ return 9
+ }
+ local new_url=${protocol:-http://}$domain$selected
+ elif [[ $selected = (#i)(http(s|)|ftp(s|)|ssh|scp)://* ]]; then
+ local new_url=$selected
+ else
+ local -a exts
+ exts=(
+ asp aspx cfm cgi ece htm
+ html htmls jhtml js jsp jspx
+ php php3 php4 phtml pl py
+ rb rhtml shtml xhtml
+ )
+ if [[ $dlpage = *.(${(~j:|:)exts}) ]]; then
+ local new_url=${dlpage:h}/$selected
+ else
+ local new_url=$dlpage/$selected
+ fi
+ fi
+ # Assign in case a dlink0 given (i.e.: that this URL was the dlink0 URL)
dlpage=$new_url
-}
+ fi
-# Handle the update
-if [[ $__subtype == update(|:*) && -z $opts[(r)-f] ]] {
+ # Handle the update
+ if [[ $__subtype == update(|:*) && -z $opts[(r)-f] ]] {
{ local old_url="$(<$__dir/._zinit/url_rsvd)"; } 2>/dev/null
[[ $old_url == $new_url ]] && return 8
-}
+ }
-# Assign outer-scope parameters
-url=$new_url
-ICE[url_rsvd]=$new_url
-ZINIT[annex-multi-flag:pull-active]=2
+ # Assign outer-scope parameters
+ url=$new_url
+ ICE[url_rsvd]=$new_url
+ ZINIT[annex-multi-flag:pull-active]=2
-if [[ $__subtype == update(|:*) ]] {
+ if [[ $__subtype == update(|:*) ]] {
typeset -gA OPTS
OPTS[opt_-q,--quiet]=0
+ }
+ +zinit-message "{pre}readurl annex: {msg}Matched the following URL: {url}${new_url}{rst}"
+ return 0
}
-+zinit-message "{pre}readurl annex: {msg}Matched the following URL: {url}${new_url}{rst}"
-
-return 0
-
-}
-
-# vim:ft=zsh:tw=80:sw=4:sts=4:et
+# vim:ft=zsh:sw=2:sts=2:et:foldmarker=[[[,]]]:foldmethod=marker