1 Star 0 Fork 0

asddfdf/zinit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zinit-install.zsh 102.71 KB
一键复制 编辑 原始数据 按行查看 历史
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4;
# -*-
# Copyright (c) 2016-2020 Sebastian Gniazdowski and contributors.
builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
builtin print -P "${ZINIT[col-error]}ERROR:%f%b Couldn't find ${ZINIT[col-obj]}zinit-side.zsh%f%b."
return 1
}
# FUNCTION: .zinit-jq-check [[[
# Check if jq is available and outputs an error message with instructions if
# that's not the case
.zinit-jq-check() {
command -v jq >/dev/null && return 0
+zinit-message "{error}❌ ERROR: jq binary not found" \
"{nl}{u-warn}Please install jq:{rst}" \
"https://github.com/stedolan/jq" \
"{nl}{u-warn}To do so with zinit, please refer to:{rst}" \
"https://github.com/zdharma-continuum/zinit/wiki/%F0%9F%A7%8A-Recommended-ices#jq"
return 1
} # ]]]
# FUNCTION: .zinit-json-get-value [[[
# Wrapper around jq that return the value of a property
# $1: JSON structure
# $2: jq path
.zinit-json-get-value() {
.zinit-jq-check || return 1
local jsonstr=$1 jqpath=$2
jq -er ".${jqpath}" <<< "$jsonstr"
} # ]]]
# FUNCTION: .zinit-json-to-array [[[
# Wrapper around jq that sets key/values of an associative array, replicating
# the structure of a given JSON object
# $1: JSON structure
# $2: jq path
# $3: name of the associative array to store the key/value pairs in
.zinit-json-to-array() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt localoptions noglob
.zinit-jq-check || return 1
local jsonstr=$1 jqpath=$2 varname=$3
(( ${(P)+varname} )) || typeset -gA "$varname"
# NOTE We're not using @sh for the keys on purpose. Associative
# array keys are used verbatim by zsh:
# typeset -A a; a[key]=one; a['key']=two; echo ${(k)a}
# 'key' key
local evalstr=$(command jq -er --arg varname $varname \
'.'${jqpath}' | to_entries |
map($varname + "[\(.key)]=\(.value | @sh);")[]' \
<<< "$jsonstr")
eval "$evalstr"
} # ]]]
# FUNCTION: .zinit-get-package [[[
.zinit-get-package() {
.zinit-jq-check || return 1
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
local user=$1 pkg=$2 plugin=$2 id_as=$3 dir=$4 profile=$5 \
ver=${ICE[ver]} local_path=${ZINIT[PLUGINS_DIR]}/${3//\//---} \
pkgjson tmpfile=${$(mktemp):-${TMPDIR:-/tmp}/zsh.xYzAbc123}
local URL=https://raw.githubusercontent.com/${ZINIT[PACKAGES_REPO]}/${ver:-${ZINIT[PACKAGES_BRANCH]}}/${pkg}/package.json
# Consume, ie delete the ver ice to avoid being consumed again at
# git-clone time
[[ -n "$ver" ]] && unset 'ICE[ver]'
local pro_sep="{rst}, {profile}" epro_sep="{error}, {profile}" \
tool_sep="{rst}, {cmd}" \
lhi_hl="{lhi}" profile_hl="{profile}"
trap "rmdir ${(qqq)local_path} 2>/dev/null; return 1" INT TERM QUIT HUP
trap "rmdir ${(qqq)local_path} 2>/dev/null" EXIT
# Check if we were provided with a local path to a package.json
# as in:
# zinit pack'/zp/firefox-dev/package.json:default' for firefox-dev
if [[ $profile == ./* || $profile == /* ]] {
local localpkg=1
# FIXME below only works if there are no ':' in the path
tmpfile=${profile%:*}
profile=${${${(M)profile:#*:*}:+${profile#*:}}:-default}
} elif { ! .zinit-download-file-stdout $URL 0 1 2>/dev/null > $tmpfile } {
# retry
command rm -f $tmpfile
.zinit-download-file-stdout $URL 1 1 2>/dev/null >1 $tmpfile
}
# load json from file
[[ -e $tmpfile ]] && pkgjson="$(<$tmpfile)"
# Set package name (used later in the output)
local pkgname=${${id_as##_unknown}:-${pkg:-${plugin}}}
[[ -n "$localpkg" ]] && pkgname="{pid}$pkgname{rst} {note}[$tmpfile]{rst}"
if [[ -z $pkgjson ]] {
+zinit-message "{error}❌ Error: the package {hi}${pkgname}" \
"{error}couldn't be found.{rst}"
return 1
}
# root field, where the relevant data is stored
local json_root='["zsh-data"]'
local json_ices="${json_root}[\"zinit-ices\"]"
local json_meta="${json_root}[\"plugin-info\"]"
local -a profiles
profiles=("${(@f)$(.zinit-json-get-value "$pkgjson" "${json_ices} | keys[]")}") \
|| return 1
# Check if user requested an unknown profile
if ! (( ${profiles[(I)${profile}]} )) {
# Assumption: the default profile is the first in the table (-> different color).
+zinit-message "{u-warn}Error{b-warn}:{error} the profile {apo}\`{hi}$profile{apo}\`" \
"{error}couldn't be found, aborting. Available profiles are:" \
"{lhi}${(pj:$epro_sep:)profiles[@]}{error}.{rst}"
return 1
}
local json_profile="${json_ices}[\"${profile}\"]"
local -A metadata
.zinit-json-to-array "$pkgjson" "$json_meta" metadata
if [[ "$?" -ne 0 || -z "$metadata" ]] {
+zinit-message '{error}❌ ERROR: Failed to retrieve metadata from package.json'
return 1
}
local user=${metadata[user]} plugin=${metadata[plugin]} \
message=${metadata[message]} url=${metadata[url]}
.zinit-json-to-array "$pkgjson" "$json_profile" ICE
local -a requirements
# FIXME requires shouldn't be stored under zinit-ices...
if [[ -n "$ICE[requires]" ]] {
# split requirements on ';'
requirements=(${(s.;.)${ICE[requires]}})
unset 'ICE[requires]'
}
[[ ${ICE[as]} == program ]] && ICE[as]="command"
[[ -n ${ICE[on-update-of]} ]] && ICE[subscribe]="${ICE[subscribe]:-${ICE[on-update-of]}}"
[[ -n ${ICE[pick]} ]] && ICE[pick]="${ICE[pick]//\$ZPFX/${ZPFX%/}}"
# FIXME Do we even need that? If yes, we may want to do that in
# .zinit-json-to-array
if [[ -n ${ICE[id-as]} ]] {
@zinit-substitute 'ICE[id-as]'
local -A map
map=( "\"" "\\\"" "\\" "\\" )
eval "ICE[id-as]=\"${ICE[id-as]//(#m)[\"\\]/${map[$MATCH]}}\""
}
+zinit-message "{info3}Package{ehi}:{rst} ${pkgname}. Selected" \
"profile{ehi}:{rst} {hi}$profile{rst}. Available" \
"profiles:${${${(M)profile:#default}:+$lhi_hl}:-$profile_hl}" \
"${(pj:$pro_sep:)profiles[@]}{rst}."
if [[ $profile != *bgn* && -n ${(M)profiles[@]:#*bgn*} ]] {
+zinit-message "{note}Note:{rst} The {apo}\`{profile}bgn{glob}*{apo}\`{rst}" \
"profiles (if any are available) are the recommended ones (the reason" \
"is that they expose the binaries provided by the package without" \
"altering (i.e.: {slight}cluttering{rst}{}) the {var}\$PATH{rst}" \
"environment variable)."
}
local required
for required ( $requirements ) {
if [[ $required == (bgn|dl|monitor) ]]; then
if [[ ( $required == bgn && -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: zinit-annex-bin-gem-node *]} ) || \
( $required == dl && -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: zinit-annex-patch-dl *]} ) || \
( $required == monitor && -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: zinit-annex-readurl *]} )
]]; then
local -A namemap
namemap=( bgn bin-gem-node dl patch-dl monitor readurl )
+zinit-message -n "{u-warn}ERROR{b-warn}: {error}the "
if [[ -z ${(MS)ICE[requires]##(\;|(#s))$required(\;|(#e))} ]]; then
+zinit-message -n "{error}requested profile {apo}\`{hi}$profile{apo}\`{error} "
else
+zinit-message -n "{error}package {pid}$pkg{error} "
fi
+zinit-message '{error}requires the {apo}`{annex}'${namemap[$required]}'{apo}`' \
"{error}annex, which is currently not installed." \
"{nl}{nl}If you'd like to install it, you can visit its homepage:" \
"{nl}– {url}https://github.com/zdharma-continuum/zinit-annex-${(L)namemap[$required]}{rst}" \
"{nl}for instructions."
(( ${#profiles[@]:#$profile} > 0 )) && \
+zinit-message "{nl}Other available profiles are:" \
"{profile}${(pj:$pro_sep:)${profiles[@]:#$profile}}{rst}."
return 1
fi
else
if ! command -v $required &>/dev/null; then
+zinit-message -n "{u-warn}ERROR{b-warn}: {error}the "
if [[ -n ${(MS)ICE[requires]##(\;|(#s))$required(\;|(#e))} ]]; then
+zinit-message -n "{error}requested profile {apo}\`{hi}$profile{apo}\`{error} "
else
+zinit-message -n "{error}package {pid}$pkg{error} "
fi
+zinit-message '{error}requires a {apo}`{cmd}'$required'{apo}`{error}' \
"command to be available in {var}\$PATH{error}.{rst}" \
"{nl}{error}The package cannot be installed unless the" \
"command will be available."
(( ${#profiles[@]:#$profile} > 0 )) && \
+zinit-message "{nl}Other available profiles are:" \
"{profile}${(pj:$pro_sep:)${profiles[@]:#$profile}}{rst}."
return 1
fi
fi
}
if [[ -n ${ICE[dl]} && -z ${(k)ZINIT_EXTS[(r)<-> z-annex-data: zinit-annex-patch-dl *]} ]] {
+zinit-message "{nl}{u-warn}WARNING{b-warn}:{rst} the profile uses" \
"{ice}dl''{rst} ice however there's currently no {annex}zinit-annex-patch-dl{rst}" \
"annex loaded, which provides it."
+zinit-message "The ice will be inactive, i.e.: no additional" \
"files will become downloaded (the ice downloads the given URLs)." \
"The package should still work, as it doesn't indicate to" \
"{u}{slight}require{rst} the annex."
+zinit-message "{nl}You can download the" \
"annex from its homepage at {url}https://github.com/zdharma-continuum/zinit-annex-patch-dl{rst}."
}
[[ -n ${message} ]] && +zinit-message "{info}${message}{rst}"
if (( ${+ICE[is-snippet]} )) {
reply=( "" "$url" )
REPLY=snippet
return 0
}
# FIXME This part below is a bit odd since it essentially replicates what
# the dl ice supposed to be doing.
# TL;DR below downloads whatever url is stored in the "_resolved" field
if (( !${+ICE[git]} && !${+ICE[from]} )) {
(
local -A jsondata
local URL=$(.zinit-json-get-value "$pkgjson" "_resolved")
local fname="${${URL%%\?*}:t}"
command mkdir -p $dir || {
+zinit-message "{u-warn}Error{b-warn}:{error} Couldn't create directory:" \
"{dir}$dir{error}, aborting.{rst}"
return 1
}
builtin cd -q $dir || return 1
+zinit-message "Downloading tarball for {pid}$plugin{rst}{}"
if { ! .zinit-download-file-stdout "$URL" 0 1 >! "$fname" } {
if { ! .zinit-download-file-stdout "$URL" 1 1 >! "$fname" } {
command rm -f "$fname"
+zinit-message "Download of the file {apo}\`{file}$fname{apo}\`{rst}" \
"failed. No available download tool? One of:" \
"{cmd}${(pj:$tool_sep:)${=:-curl wget lftp lynx}}{rst}."
return 1
}
}
ziextract "$fname" --move
return 0
) && {
reply=( "$user" "$plugin" )
REPLY=tarball
}
} else {
reply=( "${ICE[user]:-$user}" "${ICE[plugin]:-$plugin}" )
if [[ ${ICE[from]} = (|gh-r|github-rel) ]]; then
REPLY=github
else
REPLY=unknown
fi
}
return $?
} # ]]]
# FUNCTION: .zinit-setup-plugin-dir [[[
# Clones given plugin into PLUGIN_DIR. Supports multiple
# sites (respecting `from' and `proto' ice modifiers).
# Invokes compilation of plugin's main file.
#
# $1 - user
# $2 - plugin
.zinit-setup-plugin-dir() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal noshortloops rcquotes
local user=$1 plugin=$2 id_as=$3 remote_url_path=${1:+$1/}$2 \
local_path tpe=$4 update=$5 version=$6
if .zinit-get-object-path plugin "$id_as" && [[ -z $update ]] {
+zinit-message "{u-warn}ERROR{b-warn}:{error} A plugin named {pid}$id_as{error}" \
"already exists, aborting."
return 1
}
local_path=$REPLY
trap "rmdir ${(qqq)local_path}/._zinit ${(qqq)local_path} 2>/dev/null" EXIT
trap "rmdir ${(qqq)local_path}/._zinit ${(qqq)local_path} 2>/dev/null; return 1" INT TERM QUIT HUP
local -A sites
sites=(
github github.com
gh github.com
bitbucket bitbucket.org
bb bitbucket.org
gitlab gitlab.com
gl gitlab.com
notabug notabug.org
nb notabug.org
github-rel github.com/$remote_url_path/releases
gh-r github.com/$remote_url_path/releases
cygwin cygwin
)
ZINIT[annex-multi-flag:pull-active]=${${${(M)update:#-u}:+${ZINIT[annex-multi-flag:pull-active]}}:-2}
local -a arr
if [[ $user = _local ]]; then
builtin print "Warning: no local plugin \`$plugin\'."
builtin print "(should be located at: $local_path)"
return 1
fi
command rm -f ${TMPDIR:-/tmp}/zinit-execs.$$.lst ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst \
${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst ${TMPDIR:-/tmp}/zinit.compiled.$$.lst
if [[ $tpe != tarball ]] {
if [[ -z $update ]] {
.zinit-any-colorify-as-uspl2 "$user" "$plugin"
local pid_hl='{pid}' id_msg_part=" (at label{ehi}:{rst} {id-as}$id_as{rst}{…})"
(( $+ICE[pack] )) && local infix_m="({b}{ice}pack{apo}''{rst}) "
+zinit-message "{nl}Downloading $infix_m{pid}$user${user:+/}$plugin{…}${${${id_as:#$user/$plugin}}:+$id_msg_part}"
}
local site
[[ -n ${ICE[from]} ]] && site=${sites[${ICE[from]}]}
if [[ -z $site && ${ICE[from]} = *(gh-r|github-rel)* ]] {
site=${ICE[from]/(gh-r|github-re)/${sites[gh-r]}}
}
}
(
if [[ $site = */releases ]] {
local url=$site/${ICE[ver]}
.zinit-get-latest-gh-r-url-part "$user" "$plugin" "$url" || return $?
command mkdir -p "$local_path"
[[ -d "$local_path" ]] || return 1
(
() { setopt localoptions noautopushd; builtin cd -q "$local_path"; } || return 1
integer count
for REPLY ( $reply ) {
count+=1
url="https://github.com${REPLY}"
if [[ -d $local_path/._zinit ]] {
{ local old_version="$(<$local_path/._zinit/is_release${count:#1})"; } 2>/dev/null
old_version=${old_version/(#b)(\/[^\/]##)(#c4,4)\/([^\/]##)*/${match[2]}}
}
+zinit-message "(Requesting \`${REPLY:t}'${version:+, version $version}{…}${old_version:+ Current version: $old_version.})"
if { ! .zinit-download-file-stdout "$url" 0 1 >! "${REPLY:t}" } {
if { ! .zinit-download-file-stdout "$url" 1 1 >! "${REPLY:t}" } {
command rm -f "${REPLY:t}"
+zinit-message "Download of release for \`$remote_url_path' " \
"failed.{nl}Tried url: $url."
return 1
}
}
if .zinit-download-file-stdout "$url.sig" 2>/dev/null >! "${REPLY:t}.sig"; then
:
else
command rm -f "${REPLY:t}.sig"
fi
command mkdir -p ._zinit
[[ -d ._zinit ]] || return 2
builtin print -r -- $url >! ._zinit/url || return 3
builtin print -r -- ${REPLY} >! ._zinit/is_release${count:#1} || return 4
ziextract ${REPLY:t} ${${${#reply}:#1}:+--nobkp}
}
return $?
) || {
return 1
}
} elif [[ $site = cygwin ]] {
command mkdir -p "$local_path/._zinit"
[[ -d "$local_path" ]] || return 1
(
() { setopt localoptions noautopushd; builtin cd -q "$local_path"; } || return 1
.zinit-get-cygwin-package "$remote_url_path" || return 1
builtin print -r -- $REPLY >! ._zinit/is_release
ziextract "$REPLY"
) || return $?
} elif [[ $tpe = github ]] {
case ${ICE[proto]} in
(|https|git|http|ftp|ftps|rsync|ssh)
:zinit-git-clone() {
command git clone --progress ${(s: :)ICE[cloneopts]---recursive} \
${(s: :)ICE[depth]:+--depth ${ICE[depth]}} \
"${ICE[proto]:-https}://${site:-${ICE[from]:-github.com}}/$remote_url_path" \
"$local_path" \
--config transfer.fsckobjects=false \
--config receive.fsckobjects=false \
--config fetch.fsckobjects=false \
--config pull.rebase=false
integer retval=$?
unfunction :zinit-git-clone
return $retval
}
:zinit-git-clone |& { command ${ZINIT[BIN_DIR]}/share/git-process-output.zsh || cat; }
if (( pipestatus[1] == 141 )) {
:zinit-git-clone
integer retval=$?
if (( retval )) {
builtin print -Pr -- "$ZINIT[col-error]Clone failed (code: $ZINIT[col-obj]$retval$ZINIT[col-error]).%f%b"
return 1
}
} elif (( pipestatus[1] )) {
builtin print -Pr -- "$ZINIT[col-error]Clone failed (code: $ZINIT[col-obj]$pipestatus[1]$ZINIT[col-error]).%f%b"
return 1
}
;;
(*)
builtin print -Pr "${ZINIT[col-error]}Unknown protocol:%f%b ${ICE[proto]}."
return 1
esac
if [[ -n ${ICE[ver]} ]] {
command git -C "$local_path" checkout "${ICE[ver]}"
}
}
if [[ $update != -u ]] {
hook_rc=0
# Store ices at clone of a plugin
.zinit-store-ices "$local_path/._zinit" ICE "" "" "" ""
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
# Functions calls
"${arr[5]}" plugin "$user" "$plugin" "$id_as" "$local_path" "${${key##(zinit|z-annex) hook:}%% <->}" load
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
# note: this will effectively return the last != 0 rc
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
# Run annexes' atclone hooks (the after atclone-ice ones)
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" plugin "$user" "$plugin" "$id_as" "$local_path" "${${key##(zinit|z-annex) hook:}%% <->}"
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
}
return "$retval"
) || return $?
typeset -ga INSTALLED_EXECS
{ INSTALLED_EXECS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit-execs.$$.lst)}" ) } 2>/dev/null
# After additional executions like atclone'' - install completions (1 - plugins)
local -A OPTS
OPTS[opt_-q,--quiet]=1
[[ 0 = ${+ICE[nocompletions]} && ${ICE[as]} != null && ${+ICE[null]} -eq 0 ]] && \
.zinit-install-completions "$id_as" "" "0"
if [[ -e ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst || -e ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst ]] {
typeset -ga INSTALLED_COMPS SKIPPED_COMPS
{ INSTALLED_COMPS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst)}" ) } 2>/dev/null
{ SKIPPED_COMPS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst)}" ) } 2>/dev/null
}
if [[ -e ${TMPDIR:-/tmp}/zinit.compiled.$$.lst ]] {
typeset -ga ADD_COMPILED
{ ADD_COMPILED=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.compiled.$$.lst)}" ) } 2>/dev/null
}
# After any download – rehash the command table
# This will however miss the as"program" binaries
# as their PATH gets extended - and it is done
# later. It will however work for sbin'' ice.
(( !OPTS[opt_-p,--parallel] )) && rehash
return 0
} # ]]]
# FUNCTION: .zinit-install-completions [[[
# Installs all completions of given plugin. After that they are
# visible to `compinit'. Visible completions can be selectively
# disabled and enabled. User can access completion data with
# `clist' or `completions' subcommand.
#
# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin)
# $2 - plugin (only when $1 - i.e. user - given)
# $3 - if 1, then reinstall, otherwise only install completions that aren't there
.zinit-install-completions() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt nullglob extendedglob warncreateglobal typesetsilent noshortloops
local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}}
local reinstall=${3:-0} quiet=${${4:+1}:-0}
(( OPTS[opt_-q,--quiet] )) && quiet=1
[[ $4 = -Q ]] && quiet=2
typeset -ga INSTALLED_COMPS SKIPPED_COMPS
INSTALLED_COMPS=() SKIPPED_COMPS=()
.zinit-any-to-user-plugin "$id_as" ""
local user=${reply[-2]}
local plugin=${reply[-1]}
.zinit-any-colorify-as-uspl2 "$user" "$plugin"
local abbrev_pspec=$REPLY
.zinit-exists-physically-message "$id_as" "" || return 1
# Symlink any completion files included in plugin's directory
typeset -a completions already_symlinked backup_comps
local c cfile bkpfile
# The plugin == . is a semi-hack/trick to handle `creinstall .' properly
[[ $user == % || ( -z $user && $plugin == . ) ]] && \
completions=( "${plugin}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|*.yml|*.ri|_zsh_highlight*|/zsdoc/*|*.ps1)(DN^/) ) || \
completions=( "${ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|*.yml|*.ri|_zsh_highlight*|/zsdoc/*|*.ps1)(DN^/) )
already_symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN) )
backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) )
# Symlink completions if they are not already there
# either as completions (_fname) or as backups (fname)
# OR - if it's a reinstall
for c in "${completions[@]}"; do
cfile="${c:t}"
bkpfile="${cfile#_}"
if [[ ( -z ${already_symlinked[(r)*/$cfile]} || $reinstall = 1 ) &&
-z ${backup_comps[(r)*/$bkpfile]}
]]; then
if [[ $reinstall = 1 ]]; then
# Remove old files
command rm -f "${ZINIT[COMPLETIONS_DIR]}/$cfile" "${ZINIT[COMPLETIONS_DIR]}/$bkpfile"
fi
INSTALLED_COMPS+=( $cfile )
(( quiet )) || builtin print -Pr "Symlinking completion ${ZINIT[col-uname]}$cfile%f%b to completions directory."
command ln -fs "$c" "${ZINIT[COMPLETIONS_DIR]}/$cfile"
# Make compinit notice the change
.zinit-forget-completion "$cfile" "$quiet"
else
SKIPPED_COMPS+=( $cfile )
(( quiet )) || builtin print -Pr "Not symlinking completion \`${ZINIT[col-obj]}$cfile%f%b', it already exists."
(( quiet )) || builtin print -Pr "${ZINIT[col-info2]}Use \`${ZINIT[col-pname]}zinit creinstall $abbrev_pspec${ZINIT[col-info2]}' to force install.%f%b"
fi
done
if (( quiet == 1 && (${#INSTALLED_COMPS} || ${#SKIPPED_COMPS}) )) {
+zinit-message "{msg}Installed {num}${#INSTALLED_COMPS}" \
"{msg}completions. They are stored in the{var}" \
"\$INSTALLED_COMPS{msg} array."
if (( ${#SKIPPED_COMPS} )) {
+zinit-message "{msg}Skipped installing" \
"{num}${#SKIPPED_COMPS}{msg} completions." \
"They are stored in the {var}\$SKIPPED_COMPS{msg} array."
}
}
if (( ZSH_SUBSHELL )) {
builtin print -rl -- $INSTALLED_COMPS >! ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst
builtin print -rl -- $SKIPPED_COMPS >! ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst
}
.zinit-compinit 1 1 &>/dev/null
} # ]]]
# FUNCTION: .zinit-compinit [[[
# User-exposed `compinit' frontend which first ensures that all
# completions managed by Zinit are forgotten by Zshell. After
# that it runs normal `compinit', which should more easily detect
# Zinit's completions.
#
# No arguments.
.zinit-compinit() {
# This might be called during sourcing when setting up the plugins dir, so check that OPTS is actually existing
[[ -n $OPTS && -n ${OPTS[opt_-p,--parallel]} && $1 != 1 ]] && return
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
builtin setopt nullglob extendedglob warncreateglobal typesetsilent
integer use_C=$2
typeset -a symlinked backup_comps
local c cfile bkpfile action
symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc )
backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc )
# Delete completions if they are really there, either
# as completions (_fname) or backups (fname)
for c in "${symlinked[@]}" "${backup_comps[@]}"; do
action=0
cfile="${c:t}"
cfile="_${cfile#_}"
bkpfile="${cfile#_}"
#print -Pr "${ZINIT[col-info]}Processing completion $cfile%f%b"
.zinit-forget-completion "$cfile"
done
+zinit-message "Initializing completion ({func}compinit{rst}){…}"
command rm -f ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump}
# Workaround for a nasty trick in _vim
(( ${+functions[_vim_files]} )) && unfunction _vim_files
builtin autoload -Uz compinit
compinit ${${(M)use_C:#1}:+-C} -d ${ZINIT[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZINIT[COMPINIT_OPTS]}}"
} # ]]]
# FUNCTION: .zinit-download-file-stdout [[[
# Downloads file to stdout. Supports following backend commands:
# curl, wget, lftp, lynx. Used by snippet loading.
.zinit-download-file-stdout() {
local url="$1" restart="$2" progress="${(M)3:#1}"
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt localtraps extendedglob
# Return file directly for file:// urls, wget doesn't support this schema
if [[ "$url" =~ ^file:// ]] {
local filepath=${url##file://}
<"$filepath"
return "$?"
}
if (( restart )) {
(( ${path[(I)/usr/local/bin]} )) || \
{
path+=( "/usr/local/bin" );
trap "path[-1]=()" EXIT
}
if (( ${+commands[curl]} )); then
if [[ -n $progress ]]; then
command curl --tcp-fastopen --progress-bar -fSL "$url" 2> >($ZINIT[BIN_DIR]/share/single-line.zsh >&2) || return 1
else
command curl --tcp-fastopen -fsSL "$url" || return 1
fi
elif (( ${+commands[wget]} )); then
command wget ${${progress:--q}:#1} "$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
+zinit-message "{u-warn}ERROR{b-warn}:{rst}No download tool detected" \
"(one of: {cmd}curl{rst}, {cmd}wget{rst}, {cmd}lftp{rst}," \
"{cmd}lynx{rst})."
return 2
fi
} else {
if type curl 2>/dev/null 1>&2; then
if [[ -n $progress ]]; then
command curl --tcp-fastopen --progress-bar -fSL "$url" 2> >($ZINIT[BIN_DIR]/share/single-line.zsh >&2) || return 1
else
command curl --tcp-fastopen -fsSL "$url" || return 1
fi
elif type wget 2>/dev/null 1>&2; then
command wget ${${progress:--q}:#1} "$url" -O - || return 1
elif type lftp 2>/dev/null 1>&2; then
command lftp -c "cat $url" || return 1
else
.zinit-download-file-stdout "$url" "1" "$progress"
return $?
fi
}
return 0
} # ]]]
# FUNCTION: .zinit-get-url-mtime [[[
# For the given URL returns the date in the Last-Modified
# header as a time stamp
.zinit-get-url-mtime() {
local url="$1" IFS line header
local -a cmd
setopt localoptions localtraps
(( !${path[(I)/usr/local/bin]} )) && \
{
path+=( "/usr/local/bin" );
trap "path[-1]=()" EXIT
}
if (( ${+commands[curl]} )) || type curl 2>/dev/null 1>&2; then
cmd=(command curl --tcp-fastopen -sIL "$url")
elif (( ${+commands[wget]} )) || type wget 2>/dev/null 1>&2; then
cmd=(command wget --server-response --spider -q "$url" -O -)
else
REPLY=$(( $(date +"%s") ))
return 2
fi
"${cmd[@]}" |& command grep -i Last-Modified: | while read -r line; do
header="${${line#*, }//$'\r'}"
done
if [[ -z $header ]] {
REPLY=$(( $(date +"%s") ))
return 3
}
LANG=C TZ=UTC strftime -r -s REPLY "%d %b %Y %H:%M:%S GMT" "$header" &>/dev/null || {
REPLY=$(( $(date +"%s") ))
return 4
}
return 0
} # ]]]
# FUNCTION: .zinit-mirror-using-svn [[[
# Used to clone subdirectories from Github. If in update mode
# (see $2), then invokes `svn update', in normal mode invokes
# `svn checkout --non-interactive -q <URL>'. In test mode only
# compares remote and local revision and outputs true if update
# is needed.
#
# $1 - URL
# $2 - mode, "" - normal, "-u" - update, "-t" - test
# $3 - subdirectory (not path) with working copy, needed for -t and -u
.zinit-mirror-using-svn() {
setopt localoptions extendedglob warncreateglobal
local url="$1" update="$2" directory="$3"
(( ${+commands[svn]} )) || \
builtin print -Pr -- "${ZINIT[col-error]}Warning:%f%b Subversion not found" \
", please install it to use \`${ZINIT[col-obj]}svn%f%b' ice."
if [[ "$update" = "-t" ]]; then
(
() { setopt localoptions noautopushd; builtin cd -q "$directory"; }
local -a out1 out2
out1=( "${(f@)"$(LANG=C svn info -r HEAD)"}" )
out2=( "${(f@)"$(LANG=C svn info)"}" )
out1=( "${(M)out1[@]:#Revision:*}" )
out2=( "${(M)out2[@]:#Revision:*}" )
[[ "${out1[1]##[^0-9]##}" != "${out2[1]##[^0-9]##}" ]] && return 0
return 1
)
return $?
fi
if [[ "$update" = "-u" && -d "$directory" && -d "$directory/.svn" ]]; then
( () { setopt localoptions noautopushd; builtin cd -q "$directory"; }
command svn update
return $? )
else
command svn checkout --non-interactive -q "$url" "$directory"
fi
return $?
} # ]]]
# FUNCTION: .zinit-forget-completion [[[
# Implements alternation of Zsh state so that already initialized
# completion stops being visible to Zsh.
#
# $1 - completion function name, e.g. "_cp"; can also be "cp"
.zinit-forget-completion() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob typesetsilent warncreateglobal
local f="$1" quiet="$2"
typeset -a commands
commands=( ${(k)_comps[(Re)$f]} )
[[ "${#commands}" -gt 0 ]] && (( quiet == 0 )) && builtin print -Prn "Forgetting commands completed by \`${ZINIT[col-obj]}$f%f%b': "
local k
integer first=1
for k ( $commands ) {
unset "_comps[$k]"
(( quiet )) || builtin print -Prn "${${first:#1}:+, }${ZINIT[col-info]}$k%f%b"
first=0
}
(( quiet || first )) || builtin print
unfunction -- 2>/dev/null "$f"
} # ]]]
# FUNCTION: .zinit-compile-plugin [[[
# Compiles given plugin (its main source file, and also an
# additional "....zsh" file if it exists).
#
# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin)
# $2 - plugin (only when $1 - i.e. user - given)
.zinit-compile-plugin() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
builtin setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}} first plugin_dir filename is_snippet
local -a list
local -A ICE
.zinit-compute-ice "$id_as" "pack" \
ICE plugin_dir filename is_snippet || return 1
if [[ ${ICE[pick]} != /dev/null && ${ICE[as]} != null && \
${+ICE[null]} -eq 0 && ${ICE[as]} != command && ${+ICE[binary]} -eq 0 && \
( ${+ICE[nocompile]} = 0 || ${ICE[nocompile]} = \! )
]] {
reply=()
if [[ -n ${ICE[pick]} ]]; then
list=( ${~${(M)ICE[pick]:#/*}:-$plugin_dir/$ICE[pick]}(DN) )
if [[ ${#list} -eq 0 ]] {
builtin print "No files for compilation found (pick-ice didn't match)."
return 1
}
reply=( "${list[1]:h}" "${list[1]}" )
else
if (( is_snippet )) {
if [[ -f $plugin_dir/$filename ]] {
reply=( "$plugin_dir" $plugin_dir/$filename )
} elif { ! .zinit-first % "$plugin_dir" } {
+zinit-message "No files for compilation found."
return 1
}
} else {
.zinit-first "$1" "$2" || {
+zinit-message "No files for compilation found."
return 1
}
}
fi
local pdir_path=${reply[-2]}
first=${reply[-1]}
local fname=${first#$pdir_path/}
+zinit-message -n "{note}Note:{rst} Compiling{ehi}:{rst} {b}{file}$fname{rst}{…}"
if [[ -z ${ICE[(i)(\!|)(sh|bash|ksh|csh)]} ]] {
() {
builtin emulate -LR zsh -o extendedglob ${=${options[xtrace]:#off}:+-o xtrace}
if { ! zcompile -U "$first" } {
+zinit-message "{msg2}Warning:{rst} Compilation failed. Don't worry, the plugin will work also without compilation."
+zinit-message "{msg2}Warning:{rst} Consider submitting an error report to Zinit or to the plugin's author."
} else {
+zinit-message " {ok}OK{rst}."
}
# Try to catch possible additional file
zcompile -U "${${first%.plugin.zsh}%.zsh-theme}.zsh" 2>/dev/null
}
}
}
if [[ -n "${ICE[compile]}" ]]; then
local -a pats
pats=( ${(s.;.)ICE[compile]} )
local pat
list=()
for pat ( $pats ) {
eval "list+=( \$plugin_dir/$~pat(N) )"
}
if [[ ${#list} -eq 0 ]] {
+zinit-message "{u-warn}Warning{b-warn}:{rst} ice {ice}compile{apo}''{rst} didn't match any files."
} else {
integer retval
for first in $list; do
() {
builtin emulate -LR zsh -o extendedglob ${=${options[xtrace]:#off}:+-o xtrace}
zcompile -U "$first"; retval+=$?
}
done
builtin print -rl -- ${list[@]#$plugin_dir/} >! ${TMPDIR:-/tmp}/zinit.compiled.$$.lst
if (( retval )) {
+zinit-message "{note}Note:{rst} The additional {num}${#list}{rst} compiled files" \
"are listed in the {var}\$ADD_COMPILED{rst} array (operation exit" \
"code: {ehi}$retval{rst})."
} else {
+zinit-message "{note}Note:{rst} The additional {num}${#list}{rst} compiled files" \
"are listed in the {var}\$ADD_COMPILED{rst} array."
}
}
fi
return 0
} # ]]]
# FUNCTION: .zinit-download-snippet [[[
# Downloads snippet – either a file – with curl, wget, lftp or lynx,
# or a directory, with Subversion – when svn-ICE is active. Github
# supports Subversion protocol and allows to clone subdirectories.
# This is used to provide a layer of support for Oh-My-Zsh and Prezto.
.zinit-download-snippet() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent
local save_url=$1 url=$2 id_as=$3 local_dir=$4 dirname=$5 filename=$6 update=$7
trap "command rmdir ${(qqq)local_dir}/${(qqq)dirname} 2>/dev/null; return 1;" INT TERM QUIT HUP
local -a list arr
integer retval=0 hook_rc=0
local teleid_clean=${ICE[teleid]%%\?*}
[[ $teleid_clean == *://* ]] && \
local sname=${(M)teleid_clean##*://[^/]##(/[^/]##)(#c0,4)} || \
local sname=${${teleid_clean:h}:t}/${teleid_clean:t}
[[ $sname = */trunk* ]] && sname=${${ICE[teleid]%%/trunk*}:t}/${ICE[teleid]:t}
sname=${sname#./}
if (( ${+ICE[svn]} )) {
[[ $url = *(${(~kj.|.)${(Mk)ZINIT_1MAP:#OMZ*}}|robbyrussell*oh-my-zsh|ohmyzsh/ohmyzsh)* ]] && local ZSH=${ZINIT[SNIPPETS_DIR]}
url=${url/(#s)(#m)(${(~kj.|.)ZINIT_1MAP})/$ZINIT_1MAP[$MATCH]}
} else {
url=${url/(#s)(#m)(${(~kj.|.)ZINIT_2MAP})/$ZINIT_2MAP[$MATCH]}
if [[ $save_url == (${(~kj.|.)${(Mk)ZINIT_1MAP:#OMZ*}})* ]] {
if [[ $url != *.zsh(|-theme) && $url != */_[^/]## ]] {
if [[ $save_url == OMZT::* ]] {
url+=.zsh-theme
} else {
url+=/${${url#*::}:t}.plugin.zsh
}
}
} elif [[ $save_url = (${(~kj.|.)${(kM)ZINIT_1MAP:#PZT*}})* ]] {
if [[ $url != *.zsh && $url != */_[^/]## ]] {
url+=/init.zsh
}
}
}
# Change the url to point to raw github content if it isn't like that
if [[ "$url" = *github.com* && ! "$url" = */raw/* && "${+ICE[svn]}" = "0" ]] {
url="${${url/\/blob\///raw/}/\/tree\///raw/}"
}
command rm -f ${TMPDIR:-/tmp}/zinit-execs.$$.lst ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst \
${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst ${TMPDIR:-/tmp}/zinit.compiled.$$.lst
if [[ ! -d $local_dir/$dirname ]]; then
local id_msg_part="{…} (at label{ehi}:{rst} {id-as}$id_as{rst})"
[[ $update != -u ]] && +zinit-message "{nl}{info}Setting up snippet:" \
"{url}$sname{rst}${ICE[id-as]:+$id_msg_part}"
command mkdir -p "$local_dir"
fi
if [[ $update = -u && ${OPTS[opt_-q,--quiet]} != 1 ]]; then
local id_msg_part="{…} (identified as{ehi}:{rst} {id-as}$id_as{rst})"
+zinit-message "{nl}{info2}Updating snippet: {url}$sname{rst}${ICE[id-as]:+$id_msg_part}"
fi
# A flag for the annexes. 0 – no new commits, 1 - run-atpull mode,
# 2 – full update/there are new commits to download, 3 - full but
# a forced download (i.e.: the medium doesn't allow to peek update)
#
# The below inherits the flag if it's an update call (i.e.: -u given),
# otherwise it sets it to 2 – a new download is treated like a full
# update.
ZINIT[annex-multi-flag:pull-active]=${${${(M)update:#-u}:+${ZINIT[annex-multi-flag:pull-active]}}:-2}
(
if [[ $url = (http|https|ftp|ftps|scp)://* ]] {
# URL
(
() { setopt localoptions noautopushd; builtin cd -q "$local_dir"; } || return 4
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "Downloading {apo}\`{url}$sname{apo}\`{rst}${${ICE[svn]+" (with Subversion)"}:-" (with curl, wget, lftp)"}{…}"
if (( ${+ICE[svn]} )) {
if [[ $update = -u ]] {
# Test if update available
if ! .zinit-mirror-using-svn "$url" "-t" "$dirname"; then
if (( ${+ICE[run-atpull]} || OPTS[opt_-u,--urge] )) {
ZINIT[annex-multi-flag:pull-active]=1
} else { return 0; } # Will return when no updates so atpull''
# code below doesn't need any checks.
# This return 0 statement also sets the
# pull-active flag outside this subshell.
else
ZINIT[annex-multi-flag:pull-active]=2
fi
# Run annexes' atpull hooks (the before atpull-ice ones).
# The SVN block.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update:svn
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
if (( ZINIT[annex-multi-flag:pull-active] == 2 )) {
# Do the update
# The condition is reversed on purpose – to show only
# the messages on an actual update
if (( OPTS[opt_-q,--quiet] )); then
local id_msg_part="{…} (identified as{ehi}: {id-as}$id_as{rst})"
+zinit-message "{nl}{info2}Updating snippet {url}${sname}{rst}${ICE[id-as]:+$id_msg_part}"
+zinit-message "Downloading {apo}\`{rst}$sname{apo}\`{rst} (with Subversion){…}"
fi
.zinit-mirror-using-svn "$url" "-u" "$dirname" || return 4
}
} else {
.zinit-mirror-using-svn "$url" "" "$dirname" || return 4
}
# Redundant code, just to compile SVN snippet
if [[ ${ICE[as]} != command ]]; then
if [[ -n ${ICE[pick]} ]]; then
list=( ${(M)~ICE[pick]##/*}(DN) $local_dir/$dirname/${~ICE[pick]}(DN) )
elif [[ -z ${ICE[pick]} ]]; then
list=(
$local_dir/$dirname/*.plugin.zsh(DN) $local_dir/$dirname/*.zsh-theme(DN) $local_dir/$dirname/init.zsh(DN)
$local_dir/$dirname/*.zsh(DN) $local_dir/$dirname/*.sh(DN) $local_dir/$dirname/.zshrc(DN)
)
fi
if [[ -e ${list[1]} && ${list[1]} != */dev/null && \
-z ${ICE[(i)(\!|)(sh|bash|ksh|csh)]} && \
${+ICE[nocompile]} -eq 0
]] {
() {
builtin emulate -LR zsh -o extendedglob ${=${options[xtrace]:#off}:+-o xtrace}
zcompile -U "${list[1]}" &>/dev/null || \
+zinit-message "{u-warn}Warning{b-warn}:{rst} couldn't compile {apo}\`{file}${list[1]}{apo}\`{rst}."
}
}
fi
return $ZINIT[annex-multi-flag:pull-active]
} else {
command mkdir -p "$local_dir/$dirname"
if (( !OPTS[opt_-f,--force] )) {
.zinit-get-url-mtime "$url"
} else {
REPLY=$EPOCHSECONDS
}
# Returned is: modification time of the remote file.
# Thus, EPOCHSECONDS - REPLY is: allowed window for the
# local file to be modified in. ms-$secs is: files accessed
# within last $secs seconds. Thus, if there's no match, the
# local file is out of date.
local secs=$(( EPOCHSECONDS - REPLY ))
# Guard so that it's positive
(( $secs >= 0 )) || secs=0
integer skip_dl
local -a matched
matched=( $local_dir/$dirname/$filename(DNms-$secs) )
if (( ${#matched} )) {
+zinit-message "{info}Already up to date.{rst}"
# Empty-update return-short path – it also decides the
# pull-active flag after the return from this sub-shell
(( ${+ICE[run-atpull]} || OPTS[opt_-u,--urge] )) && skip_dl=1 || return 0
}
if [[ ! -f $local_dir/$dirname/$filename ]] {
ZINIT[annex-multi-flag:pull-active]=2
} else {
# secs > 1 → the file is outdated, then:
# - if true, then the mode is 2 minus run-atpull-activation,
# - if false, then mode is 3 → a forced download (no remote mtime found).
ZINIT[annex-multi-flag:pull-active]=$(( secs > 1 ? (2 - skip_dl) : 3 ))
}
# Run annexes' atpull hooks (the before atpull-ice ones).
# The URL-snippet block.
if [[ $update = -u && $ZINIT[annex-multi-flag:pull-active] -ge 1 ]] {
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update:url
hook_rc="$?"
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
}
if (( !skip_dl )) {
if { ! .zinit-download-file-stdout "$url" 0 1 >! "$dirname/$filename" } {
if { ! .zinit-download-file-stdout "$url" 1 1 >! "$dirname/$filename" } {
command rm -f "$dirname/$filename"
+zinit-message "{u-warn}ERROR{b-warn}:{rst} Download failed."
return 4
}
}
}
return $ZINIT[annex-multi-flag:pull-active]
}
)
retval=$?
# Overestimate the pull-level to 2 also in error situations
# – no hooks will be run anyway because of the error
ZINIT[annex-multi-flag:pull-active]=$retval
if [[ $ICE[as] != command && ${+ICE[svn]} -eq 0 ]] {
local file_path=$local_dir/$dirname/$filename
if [[ -n ${ICE[pick]} ]]; then
list=( ${(M)~ICE[pick]##/*}(DN) $local_dir/$dirname/${~ICE[pick]}(DN) )
file_path=${list[1]}
fi
if [[ -e $file_path && -z ${ICE[(i)(\!|)(sh|bash|ksh|csh)]} && \
$file_path != */dev/null && ${+ICE[nocompile]} -eq 0
]] {
() {
builtin emulate -LR zsh -o extendedglob ${=${options[xtrace]:#off}:+-o xtrace}
if ! zcompile -U "$file_path" 2>/dev/null; then
builtin print -r "Couldn't compile \`${file_path:t}', it MIGHT be wrongly downloaded"
builtin print -r "(snippet URL points to a directory instead of a file?"
builtin print -r "to download directory, use preceding: zinit ice svn)."
retval=4
fi
}
}
}
} else { # Local-file snippet branch
# Local files are (yet…) forcefully copied.
ZINIT[annex-multi-flag:pull-active]=3 retval=3
# Run annexes' atpull hooks (the before atpull-ice ones).
# The local-file snippets block.
if [[ $update = -u ]] {
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-pre <->]}
${${(M)ICE[atpull]#\!}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:e-\\\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update:file
hook_rc="$?"
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
}
command mkdir -p "$local_dir/$dirname"
if [[ ! -e $url ]] {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{ehi}ERROR:{error} The source file {file}$url{error} doesn't exist.{rst}"
retval=4
}
if [[ -e $url && ! -f $url && $url != /dev/null ]] {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{ehi}ERROR:{error} The source {file}$url{error} isn't a regular file.{rst}"
retval=4
}
if [[ -e $url && ! -r $url && $url != /dev/null ]] {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{ehi}ERROR:{error} The source {file}$url{error} isn't" \
"accessible (wrong permissions).{rst}"
retval=4
}
if ! (( ${+ICE[link] )) {
if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] {
+zinit-message "{msg}Copying {file}$filename{msg}{…}{rst}"
command cp -vf "$url" "$local_dir/$dirname/$filename" || \
{ +zinit-message "{ehi}ERROR:{error} The file copying has been unsuccessful.{rst}"; retval=4; }
} else {
command cp -f "$url" "$local_dir/$dirname/$filename" &>/dev/null || \
{ +zinit-message "{ehi}ERROR:{error} The copying of {file}$filename{error} has been unsuccessful"\
"${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}"; retval=4; }
}
} else {
if (( $+commands[realpath] )) {
local rpv="$(realpath --version | head -n1 | sed -E 's/realpath (\(.*\))?//g')"
if is-at-least 8.23 $rpv; then
rel_url="$(realpath --relative-to="$local_dir/$dirname" "$url")" && \
{ url="$rel_url" }
fi
}
if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] {
+zinit-message "{msg}Linking {file}$filename{msg}{…}{rst}"
command ln -svf "$url" "$local_dir/$dirname/$filename" || \
{ +zinit-message "{ehi}ERROR:{error} The file linking has been unsuccessful.{rst}"; retval=4; }
} else {
command ln -sf "$url" "$local_dir/$dirname/$filename" &>/dev/null || \
{ +zinit-message "{ehi}ERROR:{error} The link of {file}$filename{error} has been unsuccessful"\
"${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}"; retval=4; }
}
}
}
(( retval == 4 )) && { command rmdir "$local_dir/$dirname" 2>/dev/null; return $retval; }
if [[ ${${:-$local_dir/$dirname}%%/##} != ${ZINIT[SNIPPETS_DIR]} ]] {
# Store ices at "clone" and update of snippet, SVN and single-file
local pfx=$local_dir/$dirname/._zinit
.zinit-store-ices "$pfx" ICE url_rsvd "" "$save_url" "${+ICE[svn]}"
} elif [[ -n $id_as ]] {
+zinit-message "{u-warn}Warning{b-warn}:{rst} the snippet {url}$id_as{rst} isn't" \
"fully downloaded – you should remove it with {apo}\`{cmd}zinit delete $id_as{apo}\`{rst}."
}
# Empty update short-path
if (( ZINIT[annex-multi-flag:pull-active] == 0 )) {
# Run annexes' atpull hooks (the `always' after atpull-ice ones)
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:%atpull-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:%atpull-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:%atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update:0
hook_rc="$?"
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
return $retval;
}
if [[ $update = -u ]] {
# Run annexes' atpull hooks (the before atpull-ice ones).
# The block is common to all 3 snippet types.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-pre <->]}
${${ICE[atpull]:#\!*}:+${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atpull-<-> <->]}}
${(on)ZINIT_EXTS2[(I)zinit hook:no-e-\\\!atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
} else {
# Run annexes' atclone hooks (the before atclone-ice ones)
# The block is common to all 3 snippet types.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:\\\!atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:\\\!atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" load
done
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:atclone-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:atclone-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:atclone-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" load
done
}
# Run annexes' atpull hooks (the after atpull-ice ones)
# The block is common to all 3 snippet types.
if [[ $update = -u ]] {
if (( ZINIT[annex-multi-flag:pull-active] > 0 )) {
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:atpull-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:atpull-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
}
# Run annexes' atpull hooks (the `always' after atpull-ice ones)
# The block is common to all 3 snippet types.
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:%atpull-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:%atpull-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:%atpull-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" update:$ZINIT[annex-multi-flag:pull-active]
hook_rc=$?
[[ "$hook_rc" -ne 0 ]] && {
retval="$hook_rc"
builtin print -Pr -- "${ZINIT[col-warn]}Warning:%f%b ${ZINIT[col-obj]}${arr[5]}${ZINIT[col-warn]} hook returned with ${ZINIT[col-obj]}${hook_rc}${ZINIT[col-rst]}"
}
done
}
) || return $?
typeset -ga INSTALLED_EXECS
{ INSTALLED_EXECS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit-execs.$$.lst)}" ) } 2>/dev/null
# After additional executions like atclone'' - install completions (2 - snippets)
local -A OPTS
OPTS[opt_-q,--quiet]=1
[[ 0 = ${+ICE[nocompletions]} && ${ICE[as]} != null && ${+ICE[null]} -eq 0 ]] && \
.zinit-install-completions "%" "$local_dir/$dirname" 0
if [[ -e ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst || -e ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst ]] {
typeset -ga INSTALLED_COMPS SKIPPED_COMPS
{ INSTALLED_COMPS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst)}" ) } 2>/dev/null
{ SKIPPED_COMPS=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst)}" ) } 2>/dev/null
}
if [[ -e ${TMPDIR:-/tmp}/zinit.compiled.$$.lst ]] {
typeset -ga ADD_COMPILED
{ ADD_COMPILED=( "${(@f)$(<${TMPDIR:-/tmp}/zinit.compiled.$$.lst)}" ) } 2>/dev/null
}
# After any download – rehash the command table
# This will however miss the as"program" binaries
# as their PATH gets extended - and it is done
# later. It will however work for sbin'' ice.
(( !OPTS[opt_-p,--parallel] )) && rehash
return $retval
} # ]]]
# FUNCTION: .zinit-update-snippet [[[
.zinit-update-snippet() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
local -a tmp opts
local url=$1
integer correct=0
[[ -o ksharrays ]] && correct=1
opts=( -u ) # for zinit-annex-readurl
# Create a local copy of OPTS, basically
# for zinit-annex-readurl annex
local -A ice_opts
ice_opts=( "${(kv)OPTS[@]}" )
local -A OPTS
OPTS=( "${(kv)ice_opts[@]}" )
ZINIT[annex-multi-flag:pull-active]=0 ZINIT[-r/--reset-opt-hook-has-been-run]=0
# Remove leading whitespace and trailing /
url=${${url#${url%%[! $'\t']*}}%/}
ICE[teleid]=${ICE[teleid]:-$url}
[[ ${ICE[as]} = null || ${+ICE[null]} -eq 1 || ${+ICE[binary]} -eq 1 ]] && \
ICE[pick]=${ICE[pick]:-/dev/null}
local local_dir dirname filename save_url=$url \
id_as=${ICE[id-as]:-$url}
.zinit-pack-ice "$id_as" ""
# Allow things like $OSTYPE in the URL
eval "url=\"$url\""
# - case A: called from `update --all', ICE empty, static ice will win
# - case B: called from `update', ICE packed, so it will win
tmp=( "${(Q@)${(z@)ZINIT_SICE[$id_as]}}" )
if (( ${#tmp} > 1 && ${#tmp} % 2 == 0 )) {
ICE=( "${(kv)ICE[@]}" "${tmp[@]}" )
} elif [[ -n ${ZINIT_SICE[$id_as]} ]] {
+zinit-message "{error}WARNING:{msg2} Inconsistency #3" \
"occurred, please report the string: \`{obj}${ZINIT_SICE[$id_as]}{msg2}' to the" \
"GitHub issues page: {obj}https://github.com/zdharma-continuum/zinit/issues/{msg2}.{rst}"
}
id_as=${ICE[id-as]:-$id_as}
# Oh-My-Zsh, Prezto and manual shorthands
if (( ${+ICE[svn]} )) {
[[ $url = *(${(~kj.|.)${(Mk)ZINIT_1MAP:#OMZ*}}|robbyrussell*oh-my-zsh|ohmyzsh/ohmyzsh)* ]] && local ZSH=${ZINIT[SNIPPETS_DIR]}
url=${url/(#s)(#m)(${(~kj.|.)ZINIT_1MAP})/$ZINIT_1MAP[$MATCH]}
} else {
url=${url/(#s)(#m)(${(~kj.|.)ZINIT_2MAP})/$ZINIT_2MAP[$MATCH]}
if [[ $save_url == (${(~kj.|.)${(Mk)ZINIT_1MAP:#OMZ*}})* ]] {
if [[ $url != *.zsh(|-theme) && $url != */_[^/]## ]] {
if [[ $save_url == OMZT::* ]] {
url+=.zsh-theme
} else {
url+=/${${url#*::}:t}.plugin.zsh
}
}
} elif [[ $save_url = (${(~kj.|.)${(kM)ZINIT_1MAP:#PZT*}})* ]] {
if [[ $url != *.zsh ]] {
url+=/init.zsh
}
}
}
if { ! .zinit-get-object-path snippet "$id_as" } {
+zinit-message "{msg2}Error: the snippet \`{obj}$id_as{msg2}'" \
"doesn't exist, aborting the update.{rst}"
return 1
}
filename=$reply[-2] dirname=$reply[-2] local_dir=$reply[-3]
local -a arr
local key
reply=(
${(on)ZINIT_EXTS2[(I)zinit hook:preinit-pre <->]}
${(on)ZINIT_EXTS[(I)z-annex hook:preinit-<-> <->]}
${(on)ZINIT_EXTS2[(I)zinit hook:preinit-post <->]}
)
for key in "${reply[@]}"; do
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" ${${key##(zinit|z-annex) hook:}%% <->} update || \
return $(( 10 - $? ))
done
# Download or copy the file
[[ $url = *github.com* && $url != */raw/* ]] && url=${url/\/(blob|tree)\///raw/}
.zinit-download-snippet "$save_url" "$url" "$id_as" "$local_dir" "$dirname" "$filename" "-u"
return $?
} # ]]]
# FUNCTION: .zinit-get-latest-gh-r-url-part [[[
# Gets version string of latest release of given Github
# package. Connects to Github releases page.
.zinit-get-latest-gh-r-url-part() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops
REPLY=
local user=$1 plugin=$2 urlpart=$3
if [[ -z $urlpart ]] {
local url=https://github.com/$user/$plugin/releases/$ICE[ver]
} else {
local url=https://$urlpart
}
local HAS_MUSL
if command -v musl-gcc >/dev/null 2>&1; then
HAS_MUSL='linux-musl'
elif command -v musl-gcc >/dev/null 2>&1; then
HAS_MUSL='linux-musl'
elif find /lib/ -maxdepth 1 -name '*musl*' >/dev/null 2>&1; then
HAS_MUSL='linux-musl'
else
HAS_MUSL=$MACHTYPE
fi
local -A matchstr
# Logical grouping of $CPUTYPE & $OSTYPE
matchstr=(
aarch64 '(arm64|aarch64|arm[?v]8)'
arm64 '(arm64|aarch64|arm[?v]8)'
armv5 'arm[?v]5'
armv6 'arm[?v]6'
armv7 'armv[?v]7'
amd64 '(amd|amd64|x64|x86|x86_64|64bit|)*~*(eabi(hf|)|powerpc|ppc64(le|)|[-_]mips*|aarch64|riscv(64|)|s390x|[-_.]arm*)*'
x86_64 '(amd|amd64|x64|x86|x86_64|64bit|)*~*(eabi(hf|)|powerpc|ppc64(le|)|[-_]mips*|aarch64|riscv(64|)|s390x|[-_.]arm*)*'
linux "*(linux-musl|musl|linux64|linux)*~^*(linux*${MACHTYPE}|${CPUTYPE}*linux)*"
linux-android '(apk|android|linux-android)'
linux-gnu "*(linux-musl|musl|linux)*~^*(${MACHTYPE}|${CPUTYPE}|)*"
linux-musl "*(linux-musl|musl|linux-~gnu|linux)*~^*(${MACHTYPE}|${CPUTYPE}|)*"
darwin '*((#s)|/)*(apple|darwin|mac|macos|osx|dmg)*((#e)|/)*'
cygwin '(win((dows|32|64))|cygwin)'
msys '(win((dows|32|64))|cygwin)'
windows '(win((dows|32|64))|cygwin)'
)
local -a list init_list
init_list=( ${(@f)"$( { .zinit-download-file-stdout $url || .zinit-download-file-stdout $url 1; } 2>/dev/null | \
command grep -o 'href=./'$user'/'$plugin'/releases/download/[^"]\+')"} )
init_list=( ${init_list[@]#href=?} )
local -a filtered bpicks
bpicks=( ${(s.;.)ICE[bpick]} )
[[ -z $bpicks ]] && bpicks=( "" )
local bpick
reply=()
for bpick ( "${bpicks[@]}" ) {
list=( $init_list )
if [[ -n $bpick ]] { list=( ${(M)list[@]:#(#i)*/$~bpick} ) }
# REMOVE ARTIFACTS THAT SHOULDN'T BE CONSIDERED
filtered=( ${list[@]:#(#i)*([3-6]86|md5|sig|asc|txt|vsix|sum|sha256*|pkg|.sh(#e))*} )
(( $#filtered > 0 )) && list=( ${filtered[@]} )
# FILTER .APK PACKAGES IF ANBOX PRESENT
if (( $#list > 1 && ${+commands[anbox]} == 1 )) { filtered=( ${(M)list[@]:#(#i)*${~matchstr[linux-android]}*} ) } \
else { filtered=( ${list[@]:#(#i)*${~matchstr[linux-android]}*} ) }
(( $#filtered > 0 )) && list=( ${filtered[@]} )
# FILTER .DEB PACKAGES IF DPKG-DEB PRESENT
if (( $#list > 1 && ${+commands[dpkg-deb]} == 1 )) { filtered=( ${list[@]:#(#i)*(64|)*deb(#e)} ) } \
else { filtered=( ${list[@]:#*deb(#e)} ) }
(( $#filtered > 0 )) && list=( ${filtered[@]} )
# FILTER .RPM PACKAGES IF REDHAT PACKAGE MANAGER PRESENT
if (( $#list > 1 && ${+commands[rpm]} == 1 )) { filtered=( ${list[@]:#(#i)*(64|)*rpm(#e)} ) } \
else { filtered=( ${list[@]:#*rpm(#e)} ) }
(( $#filtered > 0 )) && list=( ${filtered[@]} )
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${$(uname)}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[${$(uname)}]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
# FILTER URLS BY GENERIC OS NAME (E.G., DARWIN, LINUX, ETC.)
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*/$~HAS_MUSL} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${HAS_MUSL} \\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${OSTYPE//[0-9.]/}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[${OSTYPE//[0-9.]/}]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${MACHTYPE}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[${MACHTYPE}]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${OSTYPE//[0-9.]/}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[${OSTYPE//[0-9.]/}]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${CPUTYPE}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[${CPUTYPE}]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~matchstr[${$(uname)}]}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${matchstr[$(uname)]}\\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
if (( $#list > 1 )) {
filtered=( ${(M)list[@]:#(#i)*${~HAS_MUSL}*} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
# +zinit-message "{pre}gh-r{rst}:{info} ${HAS_MUSL} \\n{obj}${(pj:\n:)${(@)list[1,5]:t}}{rst}"
}
# FILTER URLS BY NEWEST (I.E., HIGHEST NUMBER)
if (( $#list > 1 )) {
filtered=( ${list[@]:#(#i)*.(sha[[:digit:]]#|asc)} ) && (( $#filtered > 0 )) && list=( ${filtered[@]} )
}
if (( !$#list )) {
+zinit-message -n "{pre}gh-r:{error} failed to find the correct GitHub release asset to download"
if [[ -n $bpick ]] { +zinit-message -n ", modify {obj}bpick{error}-ICE (current bpick{error}: {file}${bpick}{error})." } \
else { +zinit-message -n . }
+zinit-message '{rst}'
return 1
}
reply+=( $list[1] )
}
[[ -n $reply ]]
} # ]]]
# FUNCTION: ziextract [[[
# If the file is an archive, it is extracted by this function.
# Next stage is scanning of files with the common utility `file',
# to detect executables. They are given +x mode. There are also
# messages to the user on performed actions.
#
# $1 - url
# $2 - file
ziextract() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob typesetsilent noshortloops # warncreateglobal
local -a opt_move opt_move2 opt_norm opt_auto opt_nobkp
zparseopts -D -E -move=opt_move -move2=opt_move2 -norm=opt_norm \
-auto=opt_auto -nobkp=opt_nobkp || \
{ +zinit-message "{error}ziextract:{msg2} Incorrect options given to" \
"\`{pre}ziextract{msg2}' (available are: {meta}--auto{msg2}," \
"{meta}--move{msg2}, {meta}--move2{msg2}, {meta}--norm{msg2}," \
"{meta}--nobkp{msg2}).{rst}"; return 1; }
local file="$1" ext="$2"
integer move=${${${(M)${#opt_move}:#0}:+0}:-1} \
move2=${${${(M)${#opt_move2}:#0}:+0}:-1} \
norm=${${${(M)${#opt_norm}:#0}:+0}:-1} \
auto=${${${(M)${#opt_auto}:#0}:+0}:-1} \
nobkp=${${${(M)${#opt_nobkp}:#0}:+0}:-1}
if (( auto )) {
# First try known file extensions
local -a files
integer ret_val
files=( (#i)**/*.(zip|rar|7z|tgz|tbz|tbz2|tar.gz|tar.bz2|tar.7z|txz|tar.xz|gz|xz|tar|dmg|exe)~(*/*|.(_backup|git))/*(-.DN) )
for file ( $files ) {
ziextract "$file" $opt_move $opt_move2 $opt_norm $opt_nobkp ${${${#files}:#1}:+--nobkp}
ret_val+=$?
}
# Second, try to find the archive via `file' tool
if (( !${#files} )) {
local -aU output infiles stage2_processed archives
infiles=( **/*~(._zinit*|._backup|.git)(|/*)~*/*/*(-.DN) )
output=( ${(@f)"$(command file -- $infiles 2>&1)"} )
archives=( ${(M)output[@]:#(#i)(* |(#s))(zip|rar|xz|7-zip|gzip|bzip2|tar|exe|PE32) *} )
for file ( $archives ) {
local fname=${(M)file#(${(~j:|:)infiles}): } desc=${file#(${(~j:|:)infiles}): } type
fname=${fname%%??}
[[ -z $fname || -n ${stage2_processed[(r)$fname]} ]] && continue
type=${(L)desc/(#b)(#i)(* |(#s))(zip|rar|xz|7-zip|gzip|bzip2|tar|exe|PE32) */$match[2]}
if [[ $type = (zip|rar|xz|7-zip|gzip|bzip2|tar|exe|pe32) ]] {
(( !OPTS[opt_-q,--quiet] )) && \
+zinit-message "{pre}ziextract:{info2} Note:{rst}" \
"detected a {meta}$type{rst} archive in the file" \
"{file}$fname{rst}."
ziextract "$fname" "$type" $opt_move $opt_move2 $opt_norm --norm ${${${#archives}:#1}:+--nobkp}
integer iret_val=$?
ret_val+=iret_val
(( iret_val )) && continue
# Support nested tar.(bz2|gz|…) archives
local infname=$fname
[[ -f $fname.out ]] && fname=$fname.out
files=( *.tar(ND) )
if [[ -f $fname || -f ${fname:r} ]] {
local -aU output2 archives2
output2=( ${(@f)"$(command file -- "$fname"(N) "${fname:r}"(N) $files[1](N) 2>&1)"} )
archives2=( ${(M)output2[@]:#(#i)(* |(#s))(zip|rar|xz|7-zip|gzip|bzip2|tar|exe|PE32) *} )
local file2
for file2 ( $archives2 ) {
fname=${file2%:*} desc=${file2##*:}
local type2=${(L)desc/(#b)(#i)(* |(#s))(zip|rar|xz|7-zip|gzip|bzip2|tar|exe|PE32) */$match[2]}
if [[ $type != $type2 && \
$type2 = (zip|rar|xz|7-zip|gzip|bzip2|tar)
]] {
# TODO: if multiple archives are really in the archive,
# this might delete too soon… However, it's unusual case.
[[ $fname != $infname && $norm -eq 0 ]] && command rm -f "$infname"
(( !OPTS[opt_-q,--quiet] )) && \
+zinit-message "{pre}ziextract:{info2} Note:{rst}" \
"detected a {obj}${type2}{rst} archive in the" \
" file {file}${fname}{rst}."
ziextract "$fname" "$type2" $opt_move $opt_move2 $opt_norm ${${${#archives}:#1}:+--nobkp}
ret_val+=$?
stage2_processed+=( $fname )
if [[ $fname == *.out ]] {
[[ -f $fname ]] && command mv -f "$fname" "${fname%.out}"
stage2_processed+=( ${fname%.out} )
}
}
}
}
}
}
}
return $ret_val
}
if [[ -z $file ]] {
+zinit-message "{error}ziextract:{msg2} ERROR:{msg} argument" \
"needed (the file to extract) or the {meta}--auto{msg} option."
return 1
}
if [[ ! -e $file ]] {
+zinit-message "{error}ziextract:{msg2} ERROR:{msg}" \
"the file \`{meta}${file}{msg}' doesn't exist.{rst}"
return 1
}
if (( !nobkp )) {
command mkdir -p ._backup
command rm -rf ._backup/*(DN)
command mv -f *~(._zinit*|._backup|.git|.svn|.hg|$file)(DN) ._backup 2>/dev/null
}
.zinit-extract-wrapper() {
local file="$1" fun="$2" retval
(( !OPTS[opt_-q,--quiet] )) && \
+zinit-message "{pre}ziextract:{msg} Unpacking the files from: \`{obj}$file{msg}'{…}{rst}"
$fun; retval=$?
if (( retval == 0 )) {
local -a files
files=( *~(._zinit*|._backup|.git|.svn|.hg|$file)(DN) )
(( ${#files} && !norm )) && command rm -f "$file"
}
return $retval
}
→zinit-check() { (( ${+commands[$1]} )) || \
+zinit-message "{error}ziextract:{msg2} Error:{msg} No command {data}$1{msg}," \
"it is required to unpack {file}$2{rst}."
}
case "${${ext:+.$ext}:-$file}" in
((#i)*.zip)
→zinit-extract() { →zinit-check unzip "$file" || return 1; command unzip -o "$file"; }
;;
((#i)*.rar)
→zinit-extract() { →zinit-check unrar "$file" || return 1; command unrar x "$file"; }
;;
((#i)*.tar.bz2|(#i)*.tbz|(#i)*.tbz2)
→zinit-extract() { →zinit-check bzip2 "$file" || return 1; command bzip2 -dc "$file" | command tar -xf -; }
;;
((#i)*.tar.gz|(#i)*.tgz)
→zinit-extract() { →zinit-check gzip "$file" || return 1; command gzip -dc "$file" | command tar -xf -; }
;;
((#i)*.tar.xz|(#i)*.txz)
→zinit-extract() { →zinit-check xz "$file" || return 1; command xz -dc "$file" | command tar -xf -; }
;;
((#i)*.tar.7z|(#i)*.t7z)
→zinit-extract() { →zinit-check 7z "$file" || return 1; command 7z x -so "$file" | command tar -xf -; }
;;
((#i)*.tar)
→zinit-extract() { →zinit-check tar "$file" || return 1; command tar -xf "$file"; }
;;
((#i)*.gz|(#i)*.gzip)
if [[ $file != (#i)*.gz ]] {
command mv $file $file.gz
file=$file.gz
integer zi_was_renamed=1
}
→zinit-extract() {
→zinit-check gunzip "$file" || return 1
.zinit-get-mtime-into "$file" 'ZINIT[tmp]'
command gunzip "$file" |& command egrep -v '.out$'
integer ret=$pipestatus[1]
command touch -t "$(strftime %Y%m%d%H%M.%S $ZINIT[tmp])" "$file"
return ret
}
;;
((#i)*.bz2|(#i)*.bzip2)
# Rename file if its extension does not match "bz2". bunzip2 refuses
# to operate on files that are not named correctly.
# See https://github.com/zdharma-continuum/zinit/issues/105
if [[ $file != (#i)*.bz2 ]] {
command mv $file $file.bz2
file=$file.bz2
}
→zinit-extract() { →zinit-check bunzip2 "$file" || return 1
.zinit-get-mtime-into "$file" 'ZINIT[tmp]'
command bunzip2 "$file" |& command egrep -v '.out$'
integer ret=$pipestatus[1]
command touch -t "$(strftime %Y%m%d%H%M.%S $ZINIT[tmp])" "$file"
return ret
}
;;
((#i)*.xz)
if [[ $file != (#i)*.xz ]] {
command mv $file $file.xz
file=$file.xz
}
→zinit-extract() { →zinit-check xz "$file" || return 1
.zinit-get-mtime-into "$file" 'ZINIT[tmp]'
command xz -d "$file"
integer ret=$?
command touch -t "$(strftime %Y%m%d%H%M.%S $ZINIT[tmp])" "$file"
return ret
}
;;
((#i)*.7z|(#i)*.7-zip)
→zinit-extract() { →zinit-check 7z "$file" || return 1; command 7z x "$file" >/dev/null; }
;;
((#i)*.dmg)
→zinit-extract() {
local prog
for prog ( hdiutil cp ) { →zinit-check $prog "$file" || return 1; }
integer retval
local attached_vol="$( command hdiutil attach "$file" | \
command tail -n1 | command cut -f 3 )"
command cp -Rf ${attached_vol:-${TMPDIR:-/tmp}/acb321GEF}/*(D) .
retval=$?
command hdiutil detach $attached_vol
if (( retval )) {
+zinit-message "{error}ziextract:{msg2} WARNING:{msg}" \
"problem occurred when attempted to copy the files" \
"from the mounted image: \`{obj}${file}{msg}'.{rst}"
}
return $retval
}
;;
((#i)*.deb)
→zinit-extract() { →zinit-check dpkg-deb "$file" || return 1; command dpkg-deb -R "$file" .; }
;;
((#i)*.rpm)
→zinit-extract() { →zinit-check cpio "$file" || return 1; $ZINIT[BIN_DIR]/share/rpm2cpio.zsh "$file" | command cpio -imd --no-absolute-filenames; }
;;
((#i)*.exe|(#i)*.pe32)
→zinit-extract() {
command chmod a+x -- ./$file
./$file /S /D="`cygpath -w $PWD`"
}
;;
esac
if [[ $(typeset -f + →zinit-extract) == "→zinit-extract" ]] {
.zinit-extract-wrapper "$file" →zinit-extract || {
+zinit-message -n "{error}ziextract:{msg2} WARNING:{msg}" \
"extraction of the archive \`{file}${file}{msg}' had problems"
local -a bfiles
bfiles=( ._backup/*(DN) )
if (( ${#bfiles} && !nobkp )) {
+zinit-message -n ", restoring the previous version of the plugin/snippet"
command mv ._backup/*(DN) . 2>/dev/null
}
+zinit-message ".{rst}"
unfunction -- →zinit-extract →zinit-check 2>/dev/null
return 1
}
unfunction -- →zinit-extract →zinit-check
} else {
integer warning=1
}
unfunction -- .zinit-extract-wrapper
local -a execs
execs=( **/*~(._zinit(|/*)|.git(|/*)|.svn(|/*)|.hg(|/*)|._backup(|/*))(DN-.) )
if [[ ${#execs} -gt 0 && -n $execs ]] {
execs=( ${(@f)"$( file ${execs[@]} )"} )
execs=( "${(M)execs[@]:#[^:]##:*executable*}" )
execs=( "${execs[@]/(#b)([^:]##):*/${match[1]}}" )
}
builtin print -rl -- ${execs[@]} >! ${TMPDIR:-/tmp}/zinit-execs.$$.lst
if [[ ${#execs} -gt 0 ]] {
command chmod a+x "${execs[@]}"
if (( !OPTS[opt_-q,--quiet] )) {
if (( ${#execs} == 1 )); then
+zinit-message "{pre}ziextract:{rst}" \
"Successfully extracted and assigned +x chmod to the file:" \
"\`{obj}${execs[1]}{rst}'."
else
local sep="$ZINIT[col-rst],$ZINIT[col-obj] "
if (( ${#execs} > 7 )) {
+zinit-message "{pre}ziextract:{rst} Successfully" \
"extracted and marked executable the appropriate files" \
"({obj}${(pj:$sep:)${(@)execs[1,5]:t}},…{rst}) contained" \
"in \`{file}$file{rst}'. All the extracted" \
"{obj}${#execs}{rst} executables are" \
"available in the {msg2}INSTALLED_EXECS{rst}" \
"array."
} else {
+zinit-message "{pre}ziextract:{rst} Successfully" \
"extracted and marked executable the appropriate files" \
"({obj}${(pj:$sep:)${execs[@]:t}}{rst}) contained" \
"in \`{file}$file{rst}'."
}
fi
}
} elif (( warning )) {
+zinit-message "{pre}ziextract:" \
"{error}WARNING: {msg}didn't recognize the archive" \
"type of \`{obj}${file}{msg}'" \
"${ext:+/ {obj2}${ext}{msg} }"\
"(no extraction has been done).%f%b"
}
if (( move | move2 )) {
local -a files
files=( *~(._zinit|.git|._backup|.tmp231ABC)(DN/) )
if (( ${#files} )) {
command mkdir -p .tmp231ABC
command mv -f *~(._zinit|.git|._backup|.tmp231ABC)(D) .tmp231ABC
if (( !move2 )) {
command mv -f **/*~(*/*~*/*/*|*/*/*/*|^*/*|._zinit(|/*)|.git(|/*)|._backup(|/*))(DN) .
} else {
command mv -f **/*~(*/*~*/*/*/*|*/*/*/*/*|^*/*|._zinit(|/*)|.git(|/*)|._backup(|/*))(DN) .
}
command mv .tmp231ABC/$file . &>/dev/null
command rm -rf .tmp231ABC
}
REPLY="${${execs[1]:h}:h}/${execs[1]:t}"
} else {
REPLY="${execs[1]}"
}
return 0
} # ]]]
# FUNCTION: .zinit-extract [[[
.zinit-extract() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent
local tpe=$1 extract=$2 local_dir=$3
(
builtin cd -q "$local_dir" || \
{ +zinit-message "{error}ERROR:{msg2} The path of the $tpe" \
"(\`{file}$local_dir{msg2}') isn't accessible.{rst}"
return 1
}
local -a files
files=( ${(@)${(@s: :)${extract##(\!-|-\!|\!|-)}}//(#b)(((#s)|([^\\])[\\]([\\][\\])#)|((#s)|([^\\])([\\][\\])#)) /${match[2]:+$match[3]$match[4] }${match[5]:+$match[6]${(l:${#match[7]}/2::\\:):-} }} )
if [[ ${#files} -eq 0 && -n ${extract##(\!-|-\!|\!|-)} ]] {
+zinit-message "{error}ERROR:{msg2} The files" \
"(\`{file}${extract##(\!-|-\!|\!|-)}{msg2}')" \
"not found, cannot extract.{rst}"
return 1
} else {
(( !${#files} )) && files=( "" )
}
local file
for file ( "${files[@]}" ) {
[[ -z $extract ]] && local auto2=--auto
ziextract ${${(M)extract:#(\!|-)##}:+--auto} \
$auto2 $file \
${${(MS)extract[1,2]##-}:+--norm} \
${${(MS)extract[1,2]##\!}:+--move} \
${${(MS)extract[1,2]##\!\!}:+--move2} \
${${${#files}:#1}:+--nobkp}
}
)
} # ]]]
# FUNCTION: zpextract [[[
zpextract() { ziextract "$@"; }
# ]]]
# FUNCTION: .zinit-at-eval [[[
.zinit-at-eval() {
local atpull="$1" atclone="$2"
integer retval
@zinit-substitute atclone atpull
local cmd="$atpull"
[[ $atpull == "%atclone" ]] && cmd="$atclone"
eval "$cmd"
return "$?"
} # ]]]
# FUNCTION: .zinit-get-cygwin-package [[[
.zinit-get-cygwin-package() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
REPLY=
local pkg=$1 nl=$'\n'
integer retry=3
#
# Download mirrors.lst
#
+zinit-message "{info}Downloading{ehi}: {obj}mirrors.lst{info}{…}{rst}"
local mlst="$(mktemp)"
while (( retry -- )) {
if ! .zinit-download-file-stdout https://cygwin.com/mirrors.lst 0 > $mlst; then
.zinit-download-file-stdout https://cygwin.com/mirrors.lst 1 > $mlst
fi
local -a mlist
mlist=( "${(@f)$(<$mlst)}" )
local mirror=${${mlist[ RANDOM % (${#mlist} + 1) ]}%%;*}
[[ -n $mirror ]] && break
}
if [[ -z $mirror ]] {
+zinit-message "{error}Couldn't download{error}: {obj}mirrors.lst {error}."
return 1
}
mirror=http://ftp.eq.uc.pt/software/pc/prog/cygwin/
#
# Download setup.ini.bz2
#
+zinit-message "{info2}Selected mirror is{error}: {url}${mirror}{rst}"
+zinit-message "{info}Downloading{ehi}: {file}setup.ini.bz2{info}{…}{rst}"
local setup="$(mktemp -u)"
retry=3
while (( retry -- )) {
if ! .zinit-download-file-stdout ${mirror}x86_64/setup.bz2 0 1 > $setup.bz2; then
.zinit-download-file-stdout ${mirror}x86_64/setup.bz2 1 1 > $setup.bz2
fi
command bunzip2 "$setup.bz2" 2>/dev/null
[[ -s $setup ]] && break
mirror=${${mlist[ RANDOM % (${#mlist} + 1) ]}%%;*}
+zinit-message "{pre}Retrying{error}: {meta}#{obj}$(( 3 - $retry ))/3, {pre}with mirror{error}: {url}${mirror}{rst}"
}
local setup_contents="$(command grep -A 26 "@ $pkg\$" "$setup")"
local urlpart=${${(S)setup_contents/(#b)*@ $pkg${nl}*install: (*)$nl*/$match[1]}%% *}
if [[ -z $urlpart ]] {
+zinit-message "{error}Couldn't find package{error}: {data2}\`{data}${pkg}{data2}'{error}.{rst}"
return 2
}
local url=$mirror/$urlpart outfile=${TMPDIR:-${TMPDIR:-/tmp}}/${urlpart:t}
#
# Download the package
#
+zinit-message "{info}Downloading{ehi}: {file}${url:t}{info}{…}{rst}"
retry=2
while (( retry -- )) {
integer retval=0
if ! .zinit-download-file-stdout $url 0 1 > $outfile; then
if ! .zinit-download-file-stdout $url 1 1 > $outfile; then
+zinit-message "{error}Couldn't download{error}: {url}${url}{error}."
retval=1
mirror=${${mlist[ RANDOM % (${#mlist} + 1) ]}%%;*}
url=$mirror/$urlpart outfile=${TMPDIR:-${TMPDIR:-/tmp}}/${urlpart:t}
if (( retry )) {
+zinit-message "{info2}Retrying, with mirror{error}: {url}${mirror}{info2}{…}{rst}"
continue
}
fi
fi
break
}
REPLY=$outfile
} # ]]]
# FUNCTION: zicp [[[
zicp() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
local -a mbegin mend match
local cmd=cp
if [[ $1 = (-m|--mv) ]] { cmd=mv; shift; }
local dir
if [[ $1 = (-d|--dir) ]] { dir=$2; shift 2; }
local arg
arg=${${(j: :)@}//(#b)(([[:space:]]~ )#(([^[:space:]]| )##)([[:space:]]~ )#(#B)(->|=>|→)(#B)([[:space:]]~ )#(#b)(([^[:space:]]| )##)|(#B)([[:space:]]~ )#(#b)(([^[:space:]]| )##))/${match[3]:+$match[3] $match[6]\;}${match[8]:+$match[8] $match[8]\;}}
(
if [[ -n $dir ]] { cd $dir || return 1; }
local a b var
integer retval
for a b ( "${(s: :)${${(@s.;.)${arg%\;}}:-* .}}" ) {
for var ( a b ) {
: ${(P)var::=${(P)var//(#b)(((#s)|([^\\])[\\]([\\][\\])#)|((#s)|([^\\])([\\][\\])#)) /${match[2]:+$match[3]$match[4] }${match[5]:+$match[6]${(l:${#match[7]}/2::\\:):-} }}}
}
if [[ $a != *\** ]] { a=${a%%/##}"/*" }
command mkdir -p ${~${(M)b:#/*}:-$ZPFX/$b}
command $cmd -f ${${(M)cmd:#cp}:+-R} $~a ${~${(M)b:#/*}:-$ZPFX/$b}
retval+=$?
}
return $retval
)
return
}
zimv() {
local dir
if [[ $1 = (-d|--dir) ]] { dir=$2; shift 2; }
zicp --mv ${dir:+--dir} $dir "$@"
} # ]]]
# FUNCTION: ∞zinit-reset-opt-hook [[[
∞zinit-reset-hook() {
# File
if [[ "$1" = plugin ]] {
local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6"
} else {
local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5"
}
if (( ( OPTS[opt_-r,--reset] && ZINIT[-r/--reset-opt-hook-has-been-run] == 0 ) || \
( ${+ICE[reset]} && ZINIT[-r/--reset-opt-hook-has-been-run] == 1 )
)) {
if (( ZINIT[-r/--reset-opt-hook-has-been-run] )) {
local msg_bit="{meta}reset{msg2} ice given{pre}" option=
} else {
local msg_bit="{meta2}-r/--reset{msg2} given to \`{meta}update{pre}'" option=1
}
if [[ $type == snippet ]] {
if (( $+ICE[svn] )) {
if [[ $skip_pull -eq 0 && -d $filename/.svn ]] {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{pre}reset ($msg_bit): {msg2}Resetting the repository ($msg_bit) with command: {rst}svn revert --recursive {…}/{file}$filename/.{rst} {…}"
command svn revert --recursive $filename/.
}
} else {
if (( ZINIT[annex-multi-flag:pull-active] >= 2 )) {
if (( !OPTS[opt_-q,--quiet] )) {
if [[ -f $local_dir/$dirname/$filename ]] {
if [[ -n $option || -z $ICE[reset] ]] {
+zinit-message "{pre}reset ($msg_bit):{msg2} Removing the snippet-file: {file}$filename{msg2} {…}{rst}"
} else {
+zinit-message "{pre}reset ($msg_bit):{msg2} Removing the snippet-file: {file}$filename{msg2}," \
"with the supplied code: {data2}$ICE[reset]{msg2} {…}{rst}"
}
if (( option )) {
command rm -f "$local_dir/$dirname/$filename"
} else {
eval "${ICE[reset]:-rm -f \"$local_dir/$dirname/$filename\"}"
}
} else {
+zinit-message "{pre}reset ($msg_bit):{msg2} The file {file}$filename{msg2} is already deleted {}{rst}"
if [[ -n $ICE[reset] && ! -n $option ]] {
+zinit-message "{pre}reset ($msg_bit):{msg2} (skipped running the provided reset-code:" \
"{data2}$ICE[reset]{msg2}){rst}"
}
}
}
} else {
[[ -f $local_dir/$dirname/$filename ]] && \
+zinit-message "{pre}reset ($msg_bit): {msg2}Skipping the removal of {file}$filename{msg2}" \
"as there is no new copy scheduled for download.{rst}" || \
+zinit-message "{pre}reset ($msg_bit): {msg2}The file {file}$filename{msg2} is already deleted" \
"and {ehi}no new download is being scheduled.{rst}"
}
}
} elif [[ $type == plugin ]] {
if (( is_release && !skip_pull )) {
if (( option )) {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{pre}reset ($msg_bit): {msg2}running: {rst}rm -rf ${${ZINIT[PLUGINS_DIR]:#[/[:space:]]##}:-${TMPDIR:-/tmp}/xyzabc312}/${${(M)${local_dir##${ZINIT[PLUGINS_DIR]}[/[:space:]]#}:#[^/]*}:-${TMPDIR:-/tmp}/xyzabc312-zinit-protection-triggered}/*"
builtin eval command rm -rf ${${ZINIT[PLUGINS_DIR]:#[/[:space:]]##}:-${TMPDIR:-/tmp}/xyzabc312}/"${${(M)${local_dir##${ZINIT[PLUGINS_DIR]}[/[:space:]]#}:#[^/]*}:-${TMPDIR:-/tmp}/xyzabc312-zinit-protection-triggered}"/*(ND)
} else {
(( !OPTS[opt_-q,--quiet] )) && +zinit-message "{pre}reset ($msg_bit): {msg2}running: {rst}${ICE[reset]:-rm -rf ${${ZINIT[PLUGINS_DIR]:#[/[:space:]]##}:-${TMPDIR:-/tmp}/xyzabc312}/${${(M)${local_dir##${ZINIT[PLUGINS_DIR]}[/[:space:]]#}:#[^/]*}:-${TMPDIR:-/tmp}/xyzabc312-zinit-protection-triggered}/*}"
builtin eval ${ICE[reset]:-command rm -rf ${${ZINIT[PLUGINS_DIR]:#[/[:space:]]##}:-${TMPDIR:-/tmp}/xyzabc312}/"${${(M)${local_dir##${ZINIT[PLUGINS_DIR]}[/[:space:]]#}:#[^/]*}:-${TMPDIR:-/tmp}/xyzabc312-zinit-protection-triggered}"/*(ND)}
}
} elif (( !skip_pull )) {
if (( option )) {
+zinit-message "{pre}reset ($msg_bit): {msg2}Resetting the repository with command:{rst} git reset --hard HEAD {}"
command git reset --hard HEAD
} else {
+zinit-message "{pre}reset ($msg_bit): {msg2}Resetting the repository with command:{rst} ${ICE[reset]:-git reset --hard HEAD} {}"
builtin eval "${ICE[reset]:-git reset --hard HEAD}"
}
}
}
}
if (( OPTS[opt_-r,--reset] )) {
if (( ZINIT[-r/--reset-opt-hook-has-been-run] == 1 )) {
ZINIT[-r/--reset-opt-hook-has-been-run]=0
} else {
ZINIT[-r/--reset-opt-hook-has-been-run]=1
}
} else {
# If there's no -r/--reset, pretend that it already has been served.
ZINIT[-r/--reset-opt-hook-has-been-run]=1
}
} # ]]]
# FUNCTION: ∞zinit-make-ee-hook [[[
∞zinit-make-ee-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local make=${ICE[make]}
@zinit-substitute make
(( ${+ICE[make]} )) || return 0
[[ $make = "!!"* ]] || return 0
# Git-plugin make'' at download
.zinit-countdown make && \
command make -C "$dir" ${(@s; ;)${make#\!\!}}
} # ]]]
# FUNCTION: ∞zinit-make-e-hook [[[
∞zinit-make-e-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local make=${ICE[make]}
@zinit-substitute make
(( ${+ICE[make]} )) || return 0
[[ $make = ("!"[^\!]*|"!") ]] || return 0
# Git-plugin make'' at download
.zinit-countdown make && \
command make -C "$dir" ${(@s; ;)${make#\!}}
} # ]]]
# FUNCTION: ∞zinit-make-hook [[[
∞zinit-make-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local make=${ICE[make]}
@zinit-substitute make
(( ${+ICE[make]} )) || return 0
[[ $make != "!"* ]] || return 0
# Git-plugin make'' at download
.zinit-countdown make &&
command make -C "$dir" ${(@s; ;)make}
} # ]]]
# FUNCTION: ∞zinit-atclone-hook [[[
∞zinit-atclone-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local atclone=${ICE[atclone]}
@zinit-substitute atclone
(( ${+ICE[atclone]} )) || return 0
local rc=0
[[ -n $atclone ]] && .zinit-countdown atclone && {
local ___oldcd=$PWD
(( ${+ICE[nocd]} == 0 )) && {
() {
setopt localoptions noautopushd
builtin cd -q "$dir"
}
}
eval "$atclone"
rc="$?"
() { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }
}
return "$rc"
} # ]]]
# FUNCTION: ∞zinit-extract-hook [[[
∞zinit-extract-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local extract=${ICE[extract]}
@zinit-substitute extract
(( ${+ICE[extract]} )) || return 0
.zinit-extract plugin "$extract" "$dir"
} # ]]]
# FUNCTION: ∞zinit-mv-hook [[[
∞zinit-mv-hook() {
[[ -z $ICE[mv] ]] && return 0
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
if [[ $ICE[mv] == *("->"|"")* ]] {
local from=${ICE[mv]%%[[:space:]]#(->|→)*} to=${ICE[mv]##*(->|→)[[:space:]]#} || \
} else {
local from=${ICE[mv]%%[[:space:]]##*} to=${ICE[mv]##*[[:space:]]##}
}
@zinit-substitute from to
local -a mv_args=("-f")
local -a afr
(
() { setopt localoptions noautopushd; builtin cd -q "$dir"; } || return 1
afr=( ${~from}(DN) )
if (( ! ${#afr} )) {
+zinit-message "{warn}Warning: mv ice didn't match any file. [{error}$ICE[mv]{warn}]" \
"{nl}{warn}Available files:{nl}{obj}$(ls -1)"
return 1
}
if (( !OPTS[opt_-q,--quiet] )) {
mv_args+=("-v")
}
command mv "${mv_args[@]}" "${afr[1]}" "$to"
local retval=$?
command mv "${mv_args[@]}" "${afr[1]}".zwc "$to".zwc 2>/dev/null
return $retval
)
} # ]]]
# FUNCTION: ∞zinit-cp-hook [[[
∞zinit-cp-hook() {
[[ -z $ICE[cp] ]] && return
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
if [[ $ICE[cp] == *("->"|"→")* ]] {
local from=${ICE[cp]%%[[:space:]]#(->|→)*} to=${ICE[cp]##*(->|→)[[:space:]]#} || \
} else {
local from=${ICE[cp]%%[[:space:]]##*} to=${ICE[cp]##*[[:space:]]##}
}
@zinit-substitute from to
local -a afr
( () { setopt localoptions noautopushd; builtin cd -q "$dir"; } || return 1
afr=( ${~from}(DN) )
if (( ${#afr} )) {
if (( !OPTS[opt_-q,--quiet] )) {
command cp -vf "${afr[1]}" "$to"
command cp -vf "${afr[1]}".zwc "$to".zwc 2>/dev/null
} else {
command cp -f "${afr[1]}" "$to"
command cp -f "${afr[1]}".zwc "$to".zwc 2>/dev/null
}
}
)
}
# ]]]
# FUNCTION: ∞zinit-compile-plugin-hook [[[
∞zinit-compile-plugin-hook() {
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
if ! [[ ( $hook = *\!at(clone|pull)* && ${+ICE[nocompile]} -eq 0 ) || \
( $hook = at(clone|pull)* && $ICE[nocompile] = '!' ) ]] {
return 0
}
# Compile plugin
if [[ -z $ICE[(i)(\!|)(sh|bash|ksh|csh)] ]] {
() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
setopt extendedglob warncreateglobal
if [[ $tpe == snippet ]] {
.zinit-compile-plugin "%$dir" ""
} else {
.zinit-compile-plugin "$id_as" ""
}
}
}
} # ]]]
# FUNCTION: ∞zinit-atpull-e-hook [[[
∞zinit-atpull-e-hook() {
(( ${+ICE[atpull]} )) || return 0
[[ -n ${ICE[atpull]} ]] || return 0
# Only process atpull"!cmd"
[[ $ICE[atpull] == "!"* ]] || return 0
[[ "$1" = plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local atpull=${ICE[atpull]#\!}
local rc=0
.zinit-countdown atpull && {
local ___oldcd=$PWD
(( ${+ICE[nocd]} == 0 )) && {
() { setopt localoptions noautopushd; builtin cd -q "$dir"; }
}
.zinit-at-eval "$atpull" "$ICE[atclone]"
rc="$?"
() { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; };
}
return "$rc"
} # ]]]
# FUNCTION: ∞zinit-atpull-hook [[[
∞zinit-atpull-hook() {
(( ${+ICE[atpull]} )) || return 0
[[ -n ${ICE[atpull]} ]] || return 0
# Exit early if atpull"!cmd" -> this is done by zinit-atpull-e-hook
[[ $ICE[atpull] == "!"* ]] && return 0
[[ "$1" == plugin ]] && \
local dir="${5#%}" hook="$6" subtype="$7" || \
local dir="${4#%}" hook="$5" subtype="$6"
local atpull=${ICE[atpull]}
local rc=0
.zinit-countdown atpull && {
local ___oldcd=$PWD
(( ${+ICE[nocd]} == 0 )) && {
() { setopt localoptions noautopushd; builtin cd -q "$dir"; }
}
.zinit-at-eval "$atpull" $ICE[atclone]
rc="$?"
() { setopt localoptions noautopushd; builtin cd -q "$___oldcd"; };
}
return "$rc"
} # ]]]
# FUNCTION: ∞zinit-ps-on-update-hook [[[
∞zinit-ps-on-update-hook() {
[[ -z $ICE[ps-on-update] ]] && return 0
[[ "$1" = plugin ]] && \
local tpe="$1" dir="${5#%}" hook="$6" subtype="$7" || \
local tpe="$1" dir="${4#%}" hook="$5" subtype="$6"
if (( !OPTS[opt_-q,--quiet] )) {
+zinit-message "Running $tpe's provided update code: {info}${ICE[ps-on-update][1,50]}${ICE[ps-on-update][51]:+…}{rst}"
(
builtin cd -q "$dir" || return 1
eval "$ICE[ps-on-update]"
)
} else {
(
builtin cd -q "$dir" || return 1
eval "$ICE[ps-on-update]" &> /dev/null
)
}
} # ]]]
# vim:ft=zsh:sw=4:sts=4:et:foldmarker=[[[,]]]:foldmethod=marker
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/asddfdf/zinit.git
[email protected]:asddfdf/zinit.git
asddfdf
zinit
zinit
main

搜索帮助