forked from zdharma-continuum/zinit
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zinit-install.zsh
2425 lines (2188 loc) Β· 102 KB
/
zinit-install.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- 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
+zi-log "{error}β ERROR: jq binary not found" \
"{nl}{u-warn}Please install jq:{rst}" \
"https://github.com/jqlang/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 (i.e., 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 ]] {
+zi-log "{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).
+zi-log "{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" ]] {
+zi-log '{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]}}\""
}
+zi-log "{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*} ]] {
+zi-log "{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 )
+zi-log -n "{u-warn}ERROR{b-warn}: {error}the "
if [[ -z ${(MS)ICE[requires]##(\;|(#s))$required(\;|(#e))} ]]; then
+zi-log -n "{error}requested profile {apo}\`{hi}$profile{apo}\`{error} "
else
+zi-log -n "{error}package {pid}$pkg{error} "
fi
+zi-log '{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 )) && \
+zi-log "{nl}Other available profiles are:" \
"{profile}${(pj:$pro_sep:)${profiles[@]:#$profile}}{rst}."
return 1
fi
else
if ! command -v $required &>/dev/null; then
+zi-log -n "{u-warn}ERROR{b-warn}: {error}the "
if [[ -n ${(MS)ICE[requires]##(\;|(#s))$required(\;|(#e))} ]]; then
+zi-log -n "{error}requested profile {apo}\`{hi}$profile{apo}\`{error} "
else
+zi-log -n "{error}package {pid}$pkg{error} "
fi
+zi-log '{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 )) && \
+zi-log "{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 *]} ]] {
+zi-log "{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."
+zi-log "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."
+zi-log "{nl}You can download the" \
"annex from its homepage at {url}https://github.com/zdharma-continuum/zinit-annex-patch-dl{rst}."
}
[[ -n ${message} ]] && +zi-log "{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 || {
+zi-log "{u-warn}Error{b-warn}:{error} Couldn't create directory:" \
"{dir}$dir{error}, aborting.{rst}"
return 1
}
builtin cd -q $dir || return 1
+zi-log "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"
+zi-log "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
}
}
# --move is default (or as explicit, when extract'!β¦' is given)
# Also possible is --move2 when extract'!!β¦' given
ziextract "$fname" ${ICE[extract]---move} ${${(M)ICE[extract]:#!([^!]|(#e))*}:+--move} ${${(M)ICE[extract]:#!!*}:+--move2}
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 ]] {
+zi-log "{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: {id-as}$id_as{rst})"
+zi-log "{nl}{i} Downloading {b}{file}$user${user:+/}$plugin{rst} ${${${id_as:#$user/$plugin}}:+$id_msg_part}{rst}"
}
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 tag_version=${ICE[ver]}
if [[ -z $tag_version ]]; then
tag_version="$({.zinit-download-file-stdout $site/latest || .zinit-download-file-stdout $site/latest 1;} 2>/dev/null | command grep -i -m 1 -o 'href=./'$user'/'$plugin'/releases/tag/[^"]\+')"
tag_version=${tag_version##*/}
fi
local url=$site/expanded_assets/$tag_version
.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]}}
}
+zi-log "{m} Requesting ${REPLY:t} ${version:+, version $version} ${old_version:+ Current version: $old_version.}{rst}"
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}"
+zi-log "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 && echo '*' > ._zinit/.gitignore
[[ -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} ${${(M)ICE[extract]:#!([^!]|(#e))*}:+--move} ${${(M)ICE[extract]:#!!*}:+--move2}
}
return $?
) || {
return 1
}
} elif [[ $site = cygwin ]] {
command mkdir -p "$local_path/._zinit" && echo '*' > "$local_path/._zinit/.gitignore"
[[ -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
(|ftp(|s)|git|http(|s)|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) || 0 != ${+ICE[completions]} ]] && \
.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 'completions' subcommand.
#
# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin)
# $2 - plugin if $1 (i.e., user) given
# $3 - if 1, then reinstall, otherwise only install completions that are not present
.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 the plugin 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|*.yaml|*.py|*.ri|_zsh_highlight*|/zsdoc/*|*.ps1)(DN^/) ) || \
completions=( "${ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|*.yml|*.yaml|*.py|*.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 its a reinstall
for c in "${completions[@]:A}"; 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
local comps msg
local -A comp_types=(\$INSTALLED_COMPS 'Installed' \$SKIPPED_COMPS 'Skipped re-installing')
for comps msg in ${(kv)comp_types}; do
local comps_num=${#${(e)comps}}
if (( comps_num > 0 )); then
+zi-log "{m} ${msg} {num}$comps_num{rst} completion${=${comps_num:#1}:+s}"
if (( quiet == 0 )); then
+zi-log "{m} Added $comps_num completion${=${comps_num:#1}:+s} to {var}$comps{rst} array"
fi
fi
done
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
+zi-log "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 --progress-bar -fSL "$url" 2> >(.zinit-single-line >&2) || return 1
else
command curl -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
+zi-log "{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 --progress-bar -fSL "$url" 2> >(.zinit-single-line >&2) || return 1
else
command curl -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 -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-download-snippet [[[
# Downloads snippet
# file β with curl, wget, lftp or lynx,
# 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 ]] && +zi-log "{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})"
+zi-log "{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 = (ftp(|s)|http(|s)|scp)://* ]] {
(
() { setopt localoptions noautopushd; builtin cd -q "$local_dir"; } || return 4
(( !OPTS[opt_-q,--quiet] )) && +zi-log "{i} Downloading {file}$sname{rst} ${${ICE[svn]+" (with Subversion)"}:-" (with curl, wget, lftp)"}{rst}"
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})"
+zi-log "{nl}{info2}Updating snippet {url}${sname}{rst}${ICE[id-as]:+$id_msg_part}"
+zi-log "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 || \
+zi-log "{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} )) {
+zi-log "{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 ))
}