forked from zdharma-continuum/zinit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zinit.zsh
3332 lines (2984 loc) · 150 KB
/
zinit.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
#
# zdharma-continuum/zinit/zinit.zsh
# Copyright (c) 2016-2021 Sebastian Gniazdowski
# Copyright (c) 2021-2023 zdharma-continuum
# Homepage: https://github.com/zdharma-continuum/zinit
# License: MIT License
#
#
# Main state variables.
#
typeset -gaH ZINIT_REGISTERED_PLUGINS ZINIT_TASKS ZINIT_RUN
typeset -ga zsh_loaded_plugins
if (( !${#ZINIT_TASKS} )) { ZINIT_TASKS=( "<no-data>" ); }
# Snippets loaded, url -> file name.
typeset -gAH ZINIT ZINIT_SNIPPETS ZINIT_REPORTS ZINIT_ICES ZINIT_SICE ZINIT_CUR_BIND_MAP ZINIT_EXTS ZINIT_EXTS2
typeset -gaH ZINIT_COMPDEF_REPLAY
# Compatibility with pre-rename project (Zplugin).
typeset -gAH ZPLGM
ZINIT=( "${(kv)ZPLGM[@]}" "${(kv)ZINIT[@]}" )
unset ZPLGM
#
# Common needed values.
#
[[ ! -e ${ZINIT[BIN_DIR]}/zinit.zsh ]] && ZINIT[BIN_DIR]=
# Respect the plugin standard too.
ZINIT[ZERO]="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
[[ ! -o functionargzero || ${options[posixargzero]} = on || ${ZINIT[ZERO]} != */* ]] && ZINIT[ZERO]="${(%):-%N}"
: ${ZINIT[BIN_DIR]:="${ZINIT[ZERO]:h}"}
[[ ${ZINIT[BIN_DIR]} = \~* ]] && ZINIT[BIN_DIR]=${~ZINIT[BIN_DIR]}
# Make ZINIT[BIN_DIR] path absolute.
ZINIT[BIN_DIR]="${${(M)ZINIT[BIN_DIR]:#/*}:-$PWD/${ZINIT[BIN_DIR]}}"
# Final test of ZINIT[BIN_DIR].
if [[ ! -e ${ZINIT[BIN_DIR]}/zinit.zsh ]]; then
builtin print -P "%F{196}Could not establish ZINIT[BIN_DIR] hash field. It should point where Zinit's Git repository is.%f"
return 1
fi
# User can override ZINIT[HOME_DIR].
if [[ -z ${ZINIT[HOME_DIR]} ]]; then
# Search for zinit home in the usual locations
if [[ -d ${XDG_DATA_HOME:-${HOME}/.local/share}/zinit ]]; then
ZINIT[HOME_DIR]="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit"
elif [[ -d $HOME/.zinit ]]; then
ZINIT[HOME_DIR]="$HOME/.zinit"
elif [[ -d ${ZDOTDIR:-$HOME}/.zinit ]]; then
ZINIT[HOME_DIR]="${ZDOTDIR:-$HOME}/.zinit"
elif [[ -d $HOME/.zplugin ]]; then
ZINIT[HOME_DIR]="$HOME/.zplugin"
elif [[ -d ${ZDOTDIR:-$HOME}/.zplugin ]]; then
ZINIT[HOME_DIR]="${ZDOTDIR:-$HOME}/.zplugin"
else
ZINIT[HOME_DIR]="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit"
fi
fi
if [[ -z ${ZINIT[LIST_COMMAND]} ]]; then
if (( ${+commands[exa]} )); then
ZINIT[LIST_COMMAND]='exa --color=always --tree --icons -L3'
elif (( ${+commands[tree]} )); then
ZINIT[LIST_COMMAND]='tree -L 3 -C --charset utf-8'
else
ZINIT[LIST_COMMAND]='ls --tree'
fi
fi
ZINIT[ice-list]="\
\!bash|\!csh|\!ksh|\!sh|\
aliases|as|atclone|atdelete|atinit|atload|atpull|autoload|\
bash|binary|bindmap|blockf|bpick|build|\
cloneonly|cloneopts|cmake|compile|completions|configure|countdown|cp|csh|\
debug|depth|\
extract|\
from|git|\
has|\
id-as|if|install|is-snippet|\
ksh|\
light-mode|link|load|lucid|\
make|multisrc|mv|nocd|nocompile|nocompletions|notify|null|\
on-update-of|opts|\
pack|param|pick|proto|ps-on-unload|ps-on-update|pullopts|\
reset|reset-prompt|run-atpull|\
service|sh|silent|src|subscribe|subst|svn|\
teleid|trackbinds|trigger-load|\
unload|\
ver|verbose|\
wait|wrap"
ZINIT[nval-ice-list]="\
\!bash|\!csh|\!ksh|\!sh|\
aliases|\
bash|binary|blockf|\
cloneonly|cloneopts|cmake|configure|countdown|csh|\
debug|\
git|\
is-snippet|\
ksh|\
light-mode|lucid|\
make|\
nocd|nocompile|nocompletions|notify|null|\
pullopts|\
reset|run-atpull|\
sh|silent|\
trackbinds|\
verbose"
ZINIT[cmds]="\
add-fpath|\
bindkeys|\
cclear|cd|cdclear|cdisable|cdlist|cdreplay|cenable|changes|compile|compiled|compinit|completions|create|creinstall|csearch|cuninstall|\
delete|debug|\
edit|env-whitelist|\
fpath|\
glance|\
help|--help|-h|\
ice|\
light|load|\
man|module|\
plugins|\
recall|recently|report|run|\
self-update|snippet|snippets|srv|status|stress|\
times|\
uncompile|unload|update|\
version|\
zstatus"
# Can be customized.
: ${ZINIT[COMPLETIONS_DIR]:=${ZINIT[HOME_DIR]}/completions}
: ${ZINIT[MODULE_DIR]:=${ZINIT[HOME_DIR]}/module}
: ${ZINIT[PACKAGES_BRANCH]:=HEAD}
: ${ZINIT[PACKAGES_REPO]:=zdharma-continuum/zinit-packages}
: ${ZINIT[PLUGINS_DIR]:=${ZINIT[HOME_DIR]}/plugins}
: ${ZINIT[POLARIS_DIR]:=${ZINIT[HOME_DIR]}/polaris}
: ${ZINIT[SERVICES_DIR]:=${ZINIT[HOME_DIR]}/services}
: ${ZINIT[SNIPPETS_DIR]:=${ZINIT[HOME_DIR]}/snippets}
: ${ZINIT[ZPFX]:=${ZINIT[HOME_DIR]}/polaris}
typeset -g ZPFX
: ${ZPFX:=${ZINIT[ZPFX]}}
: ${ZINIT[ALIASES_OPT]::=${${options[aliases]:#off}:+1}}
: ${ZINIT[MAN_DIR]:=${ZPFX}/man}
ZINIT[PLUGINS_DIR]=${~ZINIT[PLUGINS_DIR]} ZINIT[COMPLETIONS_DIR]=${~ZINIT[COMPLETIONS_DIR]}
ZINIT[SNIPPETS_DIR]=${~ZINIT[SNIPPETS_DIR]} ZINIT[SERVICES_DIR]=${~ZINIT[SERVICES_DIR]}
export ZPFX=${~ZPFX} ZSH_CACHE_DIR="${ZSH_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/zinit}" \
PMSPEC=0uUpiPsf
[[ -z ${path[(re)$ZPFX/bin]} ]] && [[ -d "$ZPFX/bin" ]] && path=( "$ZPFX/bin" "${path[@]}" )
[[ -z ${path[(re)$ZPFX/sbin]} ]] && [[ -d "$ZPFX/sbin" ]] && path=( "$ZPFX/sbin" "${path[@]}" )
hash -f
hash -d zinit=${ZINIT[HOME_DIR]}
hash -d plugins=${ZINIT[PLUGINS_DIR]}
hash -d zpfx=${ZINIT[HOME_DIR]}/polaris
# Add completions directory to fpath.
[[ -z ${fpath[(re)${ZINIT[COMPLETIONS_DIR]}]} ]] && fpath=( "${ZINIT[COMPLETIONS_DIR]}" "${fpath[@]}" )
[[ ! -d $ZSH_CACHE_DIR ]] && command mkdir -p "$ZSH_CACHE_DIR"
[[ -n ${ZINIT[ZCOMPDUMP_PATH]} ]] && ZINIT[ZCOMPDUMP_PATH]=${~ZINIT[ZCOMPDUMP_PATH]}
ZINIT[UPAR]=";:^[[A;:^[OA;:\\e[A;:\\eOA;:${termcap[ku]/$'\e'/^\[};:${terminfo[kcuu1]/$'\e'/^\[};:"
ZINIT[DOWNAR]=";:^[[B;:^[OB;:\\e[B;:\\eOB;:${termcap[kd]/$'\e'/^\[};:${terminfo[kcud1]/$'\e'/^\[};:"
ZINIT[RIGHTAR]=";:^[[C;:^[OC;:\\e[C;:\\eOC;:${termcap[kr]/$'\e'/^\[};:${terminfo[kcuf1]/$'\e'/^\[};:"
ZINIT[LEFTAR]=";:^[[D;:^[OD;:\\e[D;:\\eOD;:${termcap[kl]/$'\e'/^\[};:${terminfo[kcub1]/$'\e'/^\[};:"
builtin autoload -Uz is-at-least
is-at-least 5.1 && ZINIT[NEW_AUTOLOAD]=1 || ZINIT[NEW_AUTOLOAD]=0
#is-at-least 5.4 && ZINIT[NEW_AUTOLOAD]=2
# Parameters [[[
# temporary substituting of functions
ZINIT[TMP_SUBST]=inactive ZINIT[DTRACE]=0 ZINIT[CUR_PLUGIN]=
# ice
declare -gA ZINIT_1MAP ZINIT_2MAP
ZINIT_1MAP=(
OMZ:: https://github.com/ohmyzsh/ohmyzsh/trunk/
OMZP:: https://github.com/ohmyzsh/ohmyzsh/trunk/plugins/
OMZT:: https://github.com/ohmyzsh/ohmyzsh/trunk/themes/
OMZL:: https://github.com/ohmyzsh/ohmyzsh/trunk/lib/
PZT:: https://github.com/sorin-ionescu/prezto/trunk/
PZTM:: https://github.com/sorin-ionescu/prezto/trunk/modules/
)
ZINIT_2MAP=(
OMZ:: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/
OMZP:: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/plugins/
OMZT:: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/themes/
OMZL:: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/lib/
PZT:: https://raw.githubusercontent.com/sorin-ionescu/prezto/master/
PZTM:: https://raw.githubusercontent.com/sorin-ionescu/prezto/master/modules/
)
# ]]]
# Init [[[
zmodload zsh/zutil || { builtin print -P "%F{196}zsh/zutil module is required, aborting Zinit set up.%f"; return 1; }
zmodload zsh/parameter || { builtin print -P "%F{196}zsh/parameter module is required, aborting Zinit set up.%f"; return 1; }
zmodload zsh/term{cap,info} 2>/dev/null
autoload -Uz colors && colors
if [[ -z $SOURCED && ( ${+terminfo} -eq 1 && -n ${terminfo[colors]} ) || ( ${+termcap} -eq 1 && -n ${termcap[Co]} ) ]]; then
ZINIT+=(
col-annex $'\e[38;5;153m' col-faint $'\e[38;5;238m' col-msg2 $'\e[38;5;172m' col-quo $'\e[1;38;5;33m'
col-apo $'\e[1;38;5;45m' col-file $'\e[3;38;5;117m' col-msg3 $'\e[38;5;238m' col-quos $'\e[1;38;5;160m'
col-aps $'\e[38;5;117m' col-flag $'\e[1;3;38;5;79m' col-nb $'\e[22m' col-rst $'\e[0m'
col-b $'\e[1m' col-func $'\e[38;5;219m' col-nit $'\e[23m' col-slight $'\e[38;5;230m'
col-b-lhi $'\e[1m\e[38;5;75m' col-glob $'\e[38;5;227m' col-nl $'\n' col-st $'\e[9m'
col-b-warn $'\e[1;38;5;214m' col-happy $'\e[1m\e[38;5;82m' col-note $'\e[38;5;148m' col-tab $' \t '
col-bapo $'\e[1;38;5;220m' col-hi $'\e[1m\e[38;5;183m' col-nst $'\e[29m' col-term $'\e[38;5;185m'
col-baps $'\e[1;38;5;82m' col-ice $'\e[38;5;39m' col-nu $'\e[24m' col-th-bar $'\e[38;5;82m'
col-bar $'\e[38;5;82m' col-id-as $'\e[4;38;5;220m' col-num $'\e[3;38;5;155m' col-time $'\e[38;5;220m'
col-bcmd $'\e[38;5;220m' col-info $'\e[38;5;82m' col-obj $'\e[38;5;218m' col-txt $'\e[38;5;254m'
col-bspc $'\b' col-info2 $'\e[38;5;227m' col-obj2 $'\e[38;5;118m' col-u $'\e[4m'
col-cmd $'\e[38;5;82m' col-info3 $'\e[1m\e[38;5;227m' col-ok $'\e[38;5;220m' col-u-warn $'\e[4;38;5;214m'
col-data $'\e[38;5;82m' col-it $'\e[3m' col-opt $'\e[38;5;219m' col-uname $'\e[1;4m\e[35m'
col-data2 $'\e[38;5;117m' col-keyword $'\e[32m' col-p $'\e[38;5;81m' col-uninst $'\e[38;5;118m'
col-dir $'\e[3;38;5;153m' col-lhi $'\e[38;5;81m' col-pkg $'\e[1;3;38;5;27m' col-url $'\e[38;5;75m'
col-ehi $'\e[1m\e[38;5;210m' col-meta $'\e[38;5;57m' col-pname $'\e[1;4m\e[32m' col-var $'\e[38;5;81m'
col-error $'\e[1m\e[38;5;204m' col-meta2 $'\e[38;5;147m' col-pre $'\e[38;5;135m' col-version $'\e[3;38;5;87m'
col-failure $'\e[38;5;204m' col-msg $'\e[0m' col-profile $'\e[38;5;148m' col-warn $'\e[38;5;214m'
col-dbg $'\e[2m\e[38;47;107m'"[debug]"$'\e[0m'
col-e $'\e[1m\e[38;5;204m'"Error"$'\e[0m'":"
col-i $'\e[1m\e[38;5;82m'"==>"$'\e[0m'
col-m $'\e[38;5;4m'"==>"$'\e[0m'
col-w $'\e[1m\e[38;5;214m'"Warning"$'\e[0m'":"
col--… "${${${(M)LANG:#*UTF-8*}:+⋯⋯}:-···}" col-lr "${${${(M)LANG:#*UTF-8*}:+↔}:-"«-»"}"
col-ndsh "${${${(M)LANG:#*UTF-8*}:+–}:-}" col-… "${${${(M)LANG:#*UTF-8*}:+…}:-...}"
col-mdsh $'\e[1;38;5;220m'"${${${(M)LANG:#*UTF-8*}:+–}:--}"$'\e[0m'
col-mmdsh $'\e[1;38;5;220m'"${${${(M)LANG:#*UTF-8*}:+――}:--}"$'\e[0m'
col-↔ ${${${(M)LANG:#*UTF-8*}:+$'\e[38;5;82m↔\e[0m'}:-$'\e[38;5;82m«-»\e[0m'}
)
if [[ ( ${+terminfo} -eq 1 && ${terminfo[colors]} -ge 256 ) || ( ${+termcap} -eq 1 && ${termcap[Co]} -ge 256 ) ]]; then
ZINIT+=( col-pname $'\e[1;4m\e[38;5;39m' col-uname $'\e[1;4m\e[38;5;207m' )
fi
fi
# Hooks
typeset -gAH ZINIT_ZLE_HOOKS_LIST
ZINIT_ZLE_HOOKS_LIST=(
zle-isearch-exit 1
zle-isearch-update 1
zle-line-pre-redraw 1
zle-line-init 1
zle-line-finish 1
zle-history-line-set 1
zle-keymap-select 1
paste-insert 1
)
builtin setopt noaliases
# ]]]
#
# Temporary substituting of functions-related functions.
#
# FUNCTION: :zinit-reload-and-run [[[
# Marks given function ($3) for autoloading, and executes it triggering the
# load. $1 is the fpath dedicated to the function, $2 are autoload options.
# This function replaces "autoload -X", because using that on older Zsh
# versions causes problems with traps.
#
# So basically one creates function stub that calls :zinit-reload-and-run()
# instead of "autoload -X".
#
# Author: Bart Schaefer
#
# $1 - FPATH dedicated to function
# $2 - autoload options
# $3 - function name (one that needs autoloading)
:zinit-reload-and-run() {
local fpath_prefix="$1" autoload_opts="$2" func="$3"
shift 3
# Unfunction caller function (its name is given).
unfunction -- "$func"
local -a ___fpath
___fpath=( ${fpath[@]} )
local -a +h fpath
# See #127.
[[ $FPATH != *${${(@0)fpath_prefix}[1]}* ]] && \
fpath=( ${(@0)fpath_prefix} ${___fpath[@]} )
# After this the function exists again.
builtin autoload ${(s: :)autoload_opts} -- "$func"
# User wanted to call the function, not only load it.
"$func" "$@"
} # ]]]
# FUNCTION: :zinit-tmp-subst-autoload [[[
# Hijack plugin's calls to the 'autoload' builtin.
#
# The hijacking gathers report data and runs custom `autoload' function, that doesn't need FPATH.
:zinit-tmp-subst-autoload() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
builtin setopt extendedglob warncreateglobal typesetsilent rcquotes
local -a opts opts2 custom reply
local func
zparseopts -D -E -M -a opts ${(s::):-RTUXdkmrtWzwC} I+=opts2 S+:=custom
builtin set -- ${@:#--}
# Process the id-as''/teleid'' to get the plugin dir.
.zinit-any-to-user-plugin $ZINIT[CUR_USPL2]
[[ $reply[1] = % ]] && \
local PLUGIN_DIR="$reply[2]" || \
local PLUGIN_DIR="$ZINIT[PLUGINS_DIR]/${reply[1]:+$reply[1]---}${reply[2]//\//---}"
# "fpath elements" ---- those elements that lie inside the plug directory.
local -a fpath_elements
fpath_elements=( ${fpath[(r)$PLUGIN_DIR/*]} )
# Add a function subdirectory to items, if any (this action is
# according to the Plug Standard version 1.07 and later).
[[ -d $PLUGIN_DIR/functions ]] && fpath_elements+=( "$PLUGIN_DIR"/functions )
if (( ${+opts[(r)-X]} )); then
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: Failed autoload ${(j: :)opts[@]} $*"
+zi-log -u2 "{error}builtin autoload required for {obj}${(j: :)opts[@]}{error} option(s)"
return 1
fi
if (( ${+opts[(r)-w]} )); then
.zinit-add-report "${ZINIT[CUR_USPL2]}" "-w-Autoload ${(j: :)opts[@]} ${(j: :)@}"
fpath+=( $PLUGIN_DIR )
builtin autoload ${opts[@]} "$@"
return $?
fi
if [[ -n ${(M)@:#+X} ]]; then
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Autoload +X ${opts:+${(j: :)opts[@]} }${(j: :)${@:#+X}}"
local +h FPATH=$PLUGINS_DIR${fpath_elements:+:${(j.:.)fpath_elements[@]}}:$FPATH
local +h -a fpath
fpath=( $PLUGIN_DIR $fpath_elements $fpath )
builtin autoload +X ${opts[@]} "${@:#+X}"
return $?
fi
for func; do
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Autoload $func${opts:+ with options ${(j: :)opts[@]}}"
done
integer count retval
for func; do
# Real autoload doesn't touch function if it already exists.
# Author of the idea of FPATH-clean autoloading: Bart Schaefer.
if (( ${+functions[$func]} != 1 )) {
builtin setopt noaliases
if [[ $func == /* ]] && is-at-least 5.4; then
builtin autoload ${opts[@]} $func
return $?
elif [[ $func == /* ]]; then
if [[ $ZINIT[MUTE_WARNINGS] != (1|true|on|yes) && \
-z $ZINIT[WARN_SHOWN_FOR_$ZINIT[CUR_USPL2]] ]]; then
+zi-log "{u-warn}Warning{b-warn}: {rst}the plugin {pid}$ZINIT[CUR_USPL2]" \
"{rst}is using autoload functions specified by their absolute path," \
"which is not supported by this Zsh version ({↔} {version}$ZSH_VERSION{rst}," \
"required is Zsh >= {version}5.4{rst})." \
"{nl}A fallback mechanism has been applied, which works well only" \
"for functions in the plugin {u}{slight}main{rst} directory." \
"{nl}(To mute this message, set" \
"{var}\$ZINIT[MUTE_WARNINGS]{rst} to a truth value.)"
ZINIT[WARN_SHOWN_FOR_$ZINIT[CUR_USPL2]]=1
fi
# Workaround
func=$func:t
fi
if [[ ${ZINIT[NEW_AUTOLOAD]} = 2 ]]; then
builtin autoload ${opts[@]} "$PLUGIN_DIR/$func"
retval=$?
elif [[ ${ZINIT[NEW_AUTOLOAD]} = 1 ]]; then
if (( ${+opts[(r)-C]} )) {
local pth nl=$'\n' sel=""
for pth ( $PLUGIN_DIR $fpath_elements $fpath ) {
[[ -f $pth/$func ]] && { sel=$pth; break; }
}
if [[ -z $sel ]] {
+zi-log '{u-warn}zinit{b-warn}:{error} Couldn''t find autoload function{ehi}:' \
"{apo}\`{file}${func}{apo}\`{error} anywhere in {var}\$fpath{error}."
retval=1
} else {
eval "function ${(q)${custom[++count*2]}:-$func} {
local body=\"\$(<${(qqq)sel}/${(qqq)func})\" body2
() { setopt localoptions extendedglob
body2=\"\${body##[[:space:]]#${func}[[:blank:]]#\(\)[[:space:]]#\{}\"
[[ \$body2 != \$body ]] && \
body2=\"\${body2%\}[[:space:]]#([$nl]#([[:blank:]]#\#[^$nl]#((#e)|[$nl]))#)#}\"
}
functions[${${(q)custom[count*2]}:-$func}]=\"\$body2\"
${(q)${custom[count*2]}:-$func} \"\$@\"
}"
retval=$?
}
} else {
functions[$func]="
local -a fpath
fpath=( ${(qqq)PLUGIN_DIR} ${(qqq@)fpath_elements} ${(qqq@)fpath} )
builtin autoload -X ${(j: :)${(q-)opts[@]}}
"
retval=$?
}
else
eval "function ${(q)func} {
:zinit-reload-and-run ${(qqq)PLUGIN_DIR}"$'\0'"${(pj,\0,)${(qqq)fpath_elements[@]}} ${(qq)opts[*]} ${(q)func} "'"$@"
}'
retval=$?
fi
(( ZINIT[ALIASES_OPT] )) && builtin setopt aliases
}
if (( ${+opts2[(r)-I]} )) {
${custom[count*2]:-$func}
retval=$?
}
done
return $retval
} # ]]]
# FUNCTION: :zinit-tmp-subst-bindkey [[[
# Function defined to hijack plugin's calls to the `bindkey' builtin.
#
# The hijacking is to gather report data (which is used in unload).
:zinit-tmp-subst-bindkey() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
builtin setopt extendedglob warncreateglobal typesetsilent noshortloops
is-at-least 5.3 && \
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Bindkey ${(j: :)${(q+)@}}" || \
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Bindkey ${(j: :)${(q)@}}"
# Remember to perform the actual bindkey call.
typeset -a pos
pos=( "$@" )
# Check if we have regular bindkey call, i.e.
# with no options or with -s, plus possible -M
# option.
local -A opts
zparseopts -A opts -D ${(s::):-lLdDAmrsevaR} M: N:
if (( ${#opts} == 0 ||
( ${#opts} == 1 && ${+opts[-M]} ) ||
( ${#opts} == 1 && ${+opts[-R]} ) ||
( ${#opts} == 1 && ${+opts[-s]} ) ||
( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-s]} ) ||
( ${#opts} <= 2 && ${+opts[-M]} && ${+opts[-R]} )
)); then
local string="${(q)1}" widget="${(q)2}"
local quoted
if [[ -n ${ICE[bindmap]} && ${ZINIT_CUR_BIND_MAP[empty]} -eq 1 ]]; then
local -a pairs
pairs=( "${(@s,;,)ICE[bindmap]}" )
if [[ -n ${(M)pairs:#*\\(#e)} ]] {
local prev
pairs=( ${pairs[@]//(#b)((*)\\(#e)|(*))/${match[3]:+${prev:+$prev\;}}${match[3]}${${prev::=${match[2]:+${prev:+$prev\;}}${match[2]}}:+}} )
}
pairs=( "${(@)${(@)${(@s:->:)pairs}##[[:space:]]##}%%[[:space:]]##}" )
ZINIT_CUR_BIND_MAP=( empty 0 )
(( ${#pairs} > 1 && ${#pairs[@]} % 2 == 0 )) && ZINIT_CUR_BIND_MAP+=( "${pairs[@]}" )
fi
local bmap_val="${ZINIT_CUR_BIND_MAP[${1}]}"
if (( !ZINIT_CUR_BIND_MAP[empty] )) {
[[ -z $bmap_val ]] && bmap_val="${ZINIT_CUR_BIND_MAP[${(qqq)1}]}"
[[ -z $bmap_val ]] && bmap_val="${ZINIT_CUR_BIND_MAP[${(qqq)${(Q)1}}]}"
[[ -z $bmap_val ]] && { bmap_val="${ZINIT_CUR_BIND_MAP[!${(qqq)1}]}"; integer val=1; }
[[ -z $bmap_val ]] && bmap_val="${ZINIT_CUR_BIND_MAP[!${(qqq)${(Q)1}}]}"
}
if [[ -n $bmap_val ]]; then
string="${(q)bmap_val}"
if (( val )) {
[[ ${pos[1]} = "-M" ]] && pos[4]="$bmap_val" || pos[2]="$bmap_val"
} else {
[[ ${pos[1]} = "-M" ]] && pos[3]="${(Q)bmap_val}" || pos[1]="${(Q)bmap_val}"
}
.zinit-add-report "${ZINIT[CUR_USPL2]}" ":::Bindkey: combination <$1> changed to <$bmap_val>${${(M)bmap_val:#hold}:+, i.e. ${ZINIT[col-error]}unmapped${ZINIT[col-rst]}}"
((1))
elif [[ ( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[UPAR]}} && -n ${${ZINIT[UPAR]}[(r);:${(q)1};:]} ) || \
( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[DOWNAR]}} && -n ${${ZINIT[DOWNAR]}[(r);:${(q)1};:]} ) || \
( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[RIGHTAR]}} && -n ${${ZINIT[RIGHTAR]}[(r);:${(q)1};:]} ) || \
( -n ${bmap_val::=${ZINIT_CUR_BIND_MAP[LEFTAR]}} && -n ${${ZINIT[LEFTAR]}[(r);:${(q)1};:]} )
]]; then
string="${(q)bmap_val}"
if (( val )) {
[[ ${pos[1]} = "-M" ]] && pos[4]="$bmap_val" || pos[2]="$bmap_val"
} else {
[[ ${pos[1]} = "-M" ]] && pos[3]="${(Q)bmap_val}" || pos[1]="${(Q)bmap_val}"
}
.zinit-add-report "${ZINIT[CUR_USPL2]}" ":::Bindkey: combination <$1> recognized as cursor-key and changed to <${bmap_val}>${${(M)bmap_val:#hold}:+, i.e. ${ZINIT[col-error]}unmapped${ZINIT[col-rst]}}"
fi
[[ $bmap_val = hold ]] && return 0
local prev="${(q)${(s: :)$(builtin bindkey ${(Q)string})}[-1]#undefined-key}"
# "-M map" given?
if (( ${+opts[-M]} )); then
local Mopt=-M
local Marg="${opts[-M]}"
Mopt="${(q)Mopt}"
Marg="${(q)Marg}"
quoted="$string $widget $prev $Mopt $Marg"
else
quoted="$string $widget $prev"
fi
# -R given?
if (( ${+opts[-R]} )); then
local Ropt=-R
Ropt="${(q)Ropt}"
if (( ${+opts[-M]} )); then
quoted="$quoted $Ropt"
else
# Two empty fields for non-existent -M arg.
local space=_
space="${(q)space}"
quoted="$quoted $space $space $Ropt"
fi
fi
quoted="${(q)quoted}"
# Remember the bindkey, only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted "
else
# bindkey -A newkeymap main?
# Negative indices for KSH_ARRAYS immunity.
if [[ ${#opts} -eq 1 && ${+opts[-A]} = 1 && ${#pos} = 3 && ${pos[-1]} = main && ${pos[-2]} != -A ]]; then
# Save a copy of main keymap.
(( ZINIT[BINDKEY_MAIN_IDX] = ${ZINIT[BINDKEY_MAIN_IDX]:-0} + 1 ))
local pname="${ZINIT[CUR_PLUGIN]:-_dtrace}"
local name="${(q)pname}-main-${ZINIT[BINDKEY_MAIN_IDX]}"
builtin bindkey -N "$name" main
# Remember occurence of main keymap substitution, to revert on unload.
local keys=_ widget=_ prev= optA=-A mapname="${name}" optR=_
local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optA} ${(q)mapname} ${(q)optR}"
quoted="${(q)quoted}"
# Remember the bindkey, only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted "
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted "
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: keymap \`main' copied to \`${name}' because of \`${pos[-2]}' substitution"
# bindkey -N newkeymap [other].
elif [[ ${#opts} -eq 1 && ${+opts[-N]} = 1 ]]; then
local Nopt=-N
local Narg="${opts[-N]}"
local keys=_ widget=_ prev= optN=-N mapname="${Narg}" optR=_
local quoted="${(q)keys} ${(q)widget} ${(q)prev} ${(q)optN} ${(q)mapname} ${(q)optR}"
quoted="${(q)quoted}"
# Remember the bindkey, only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[BINDKEYS__${ZINIT[CUR_USPL2]}]+="$quoted "
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[BINDKEYS___dtrace/_dtrace]+="$quoted "
else
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: last bindkey used non-typical options: ${(kv)opts[*]}"
fi
fi
# Actual bindkey.
builtin bindkey "${pos[@]}"
return $? # testable
} # ]]]
# FUNCTION: :zinit-tmp-subst-zstyle [[[
# Function defined to hijack plugin's calls to the `zstyle' builtin.
#
# The hijacking is to gather report data (which is used in unload).
:zinit-tmp-subst-zstyle() {
builtin setopt localoptions noerrreturn noerrexit extendedglob nowarncreateglobal \
typesetsilent noshortloops unset
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Zstyle $*"
# Remember in order to perform the actual zstyle call.
typeset -a pos
pos=( "$@" )
# Check if we have regular zstyle call, i.e.
# with no options or with -e.
local -a opts
zparseopts -a opts -D ${(s::):-eLdgabsTtm}
if [[ ${#opts} -eq 0 || ( ${#opts} -eq 1 && ${+opts[(r)-e]} = 1 ) ]]; then
# Have to quote $1, then $2, then concatenate them, then quote them again.
local pattern="${(q)1}" style="${(q)2}"
local ps="$pattern $style"
ps="${(q)ps}"
# Remember the zstyle, only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[ZSTYLES__${ZINIT[CUR_USPL2]}]+="$ps "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[ZSTYLES___dtrace/_dtrace]+=$ps
else
if [[ ! ${#opts[@]} = 1 && ( ${+opts[(r)-s]} = 1 || ${+opts[(r)-b]} = 1 || ${+opts[(r)-a]} = 1 ||
${+opts[(r)-t]} = 1 || ${+opts[(r)-T]} = 1 || ${+opts[(r)-m]} = 1 )
]]; then
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: last zstyle used non-typical options: ${opts[*]}"
fi
fi
# Actual zstyle.
builtin zstyle "${pos[@]}"
return $? # testable
} # ]]]
# FUNCTION: :zinit-tmp-subst-alias [[[
# Function defined to hijack plugin's calls to the `alias' builtin.
#
# The hijacking is to gather report data (which is used in unload).
:zinit-tmp-subst-alias() {
builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \
typesetsilent noshortloops unset
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Alias $*"
# Remember to perform the actual alias call.
typeset -a pos
pos=( "$@" )
local -a opts
zparseopts -a opts -D ${(s::):-gs}
local a quoted tmp
for a in "$@"; do
local aname="${a%%[=]*}"
local avalue="${a#*=}"
# Check if alias is to be redefined.
(( ${+aliases[$aname]} )) && .zinit-add-report "${ZINIT[CUR_USPL2]}" "Warning: redefining alias \`${aname}', previous value: ${aliases[$aname]}"
local bname=${(q)aliases[$aname]}
aname="${(q)aname}"
if (( ${+opts[(r)-s]} )); then
tmp=-s
tmp="${(q)tmp}"
quoted="$aname $bname $tmp"
elif (( ${+opts[(r)-g]} )); then
tmp=-g
tmp="${(q)tmp}"
quoted="$aname $bname $tmp"
else
quoted="$aname $bname"
fi
quoted="${(q)quoted}"
# Remember the alias, only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[ALIASES__${ZINIT[CUR_USPL2]}]+="$quoted "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[ALIASES___dtrace/_dtrace]+="$quoted "
done
# Actual alias.
builtin alias "${pos[@]}"
return $? # testable
} # ]]]
# FUNCTION: :zinit-tmp-subst-zle [[[.
# Function defined to hijack plugin's calls to the `zle' builtin.
#
# The hijacking is to gather report data (which is used in unload).
:zinit-tmp-subst-zle() {
builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \
typesetsilent noshortloops unset
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Zle $*"
# Remember to perform the actual zle call.
typeset -a pos
pos=( "$@" )
builtin set -- "${@:#--}"
# Try to catch game-changing "-N".
if [[ ( $1 = -N && ( $# = 2 || $# = 3 ) ) || ( $1 = -C && $# = 4 ) ]]; then
# Hooks.
if [[ ${ZINIT_ZLE_HOOKS_LIST[$2]} = 1 ]]; then
local quoted="$2"
quoted="${(q)quoted}"
# Remember only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_DELETE__${ZINIT[CUR_USPL2]}]+="$quoted "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted "
# These will be saved and restored.
elif (( ${+widgets[$2]} )); then
# Have to remember original widget "$2" and
# the copy that it's going to be done.
local widname="$2" targetfun="${${${(M)1:#-C}:+$4}:-$3}"
local completion_widget="${${(M)1:#-C}:+$3}"
local saved_widcontents="${widgets[$widname]}"
widname="${(q)widname}"
completion_widget="${(q)completion_widget}"
targetfun="${(q)targetfun}"
saved_widcontents="${(q)saved_widcontents}"
local quoted="$1 $widname $completion_widget $targetfun $saved_widcontents"
quoted="${(q)quoted}"
# Remember only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_SAVED__${ZINIT[CUR_USPL2]}]+="$quoted "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_SAVED___dtrace/_dtrace]+="$quoted "
# These will be deleted.
else
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Note: a new widget created via zle -N: \`$2'"
local quoted="$2"
quoted="${(q)quoted}"
# Remember only when load is in progress (it can be dstart that leads execution here).
[[ -n ${ZINIT[CUR_USPL2]} ]] && ZINIT[WIDGETS_DELETE__${ZINIT[CUR_USPL2]}]+="$quoted "
# Remember for dtrace.
[[ ${ZINIT[DTRACE]} = 1 ]] && ZINIT[WIDGETS_DELETE___dtrace/_dtrace]+="$quoted "
fi
fi
# Actual zle.
builtin zle "${pos[@]}"
return $? # testable
} # ]]]
# FUNCTION: :zinit-tmp-subst-compdef [[[
# Function defined to hijack plugin's calls to the `compdef' function.
# The hijacking is not only for reporting, but also to save compdef
# calls so that `compinit' can be called after loading plugins.
:zinit-tmp-subst-compdef() {
builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \
typesetsilent noshortloops unset
.zinit-add-report "${ZINIT[CUR_USPL2]}" "Saving \`compdef $*' for replay"
ZINIT_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" )
return 0 # testable
} # ]]]
# FUNCTION: .zinit-tmp-subst-on [[[
# Turn on temporary substituting of functions of builtins and functions according to passed
# mode ("load", "light", "light-b" or "compdef"). The temporary substituting of functions is
# to gather report data, and to hijack 'autoload', 'bindkey' and 'compdef' calls.
.zinit-tmp-subst-on() {
local mode="$1"
# Enable temporary substituting of functions only once.
#
# One could expect possibility of widening of temporary substituting of functions, however
# such sequence doesn't exist, e.g. "light" then "load"/"dtrace", "compdef" then "load"/
# "dtrace", "light" then "compdef", "compdef" then "light".
#
# It is always "dtrace" then "load" (i.e. dtrace then load) "dtrace" then "light" (i.e.:
# dtrace then light load) "dtrace" then "compdef" (i.e.: dtrace then snippet).
[[ ${ZINIT[TMP_SUBST]} != inactive ]] && builtin return 0
ZINIT[TMP_SUBST]="$mode"
# The point about backuping is: does the key exist in functions array.
# If it does exist, then it will also exist as ZINIT[bkp-*].
# Defensive code, shouldn't be needed.
builtin unset "ZINIT[bkp-autoload]" "ZINIT[bkp-compdef]" # 0, E.
if [[ $mode != compdef ]]; then
# 0. Used, but not in temporary restoration, which doesn't happen for autoload.
(( ${+functions[autoload]} )) && ZINIT[bkp-autoload]="${functions[autoload]}"
functions[autoload]=':zinit-tmp-subst-autoload "$@";'
fi
# E. Always shade compdef.
(( ${+functions[compdef]} )) && ZINIT[bkp-compdef]="${functions[compdef]}"
functions[compdef]=':zinit-tmp-subst-compdef "$@";'
# Temporarily replace `source' if subst'' given.
if [[ -n ${ICE[subst]} ]] {
(( ${+functions[source]} )) && ZINIT[bkp-source]="${functions[source]}"
(( ${+functions[.]} )) && ZINIT[bkp-.]="${functions[.]}"
(( ${+functions[.zinit-service]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-additional.zsh"
functions[source]=':zinit-tmp-subst-source "$@";'
functions[.]=':zinit-tmp-subst-source "$@";'
}
# Light and compdef temporary substituting of functions stops here. Dtrace and load go on.
[[ ( $mode = light && ${+ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0
# Defensive code, shouldn't be needed. A, B, C, D.
builtin unset "ZINIT[bkp-bindkey]" "ZINIT[bkp-zstyle]" "ZINIT[bkp-alias]" "ZINIT[bkp-zle]"
# A.
(( ${+functions[bindkey]} )) && ZINIT[bkp-bindkey]="${functions[bindkey]}"
functions[bindkey]=':zinit-tmp-subst-bindkey "$@";'
# B, when `zinit light -b ...' or when `zinit ice trackbinds ...; zinit light ...'.
[[ $mode = light-b || ( $mode = light && ${+ICE[trackbinds]} -eq 1 ) ]] && return 0
# B.
(( ${+functions[zstyle]} )) && ZINIT[bkp-zstyle]="${functions[zstyle]}"
functions[zstyle]=':zinit-tmp-subst-zstyle "$@";'
# C.
(( ${+functions[alias]} )) && ZINIT[bkp-alias]="${functions[alias]}"
functions[alias]=':zinit-tmp-subst-alias "$@";'
# D.
(( ${+functions[zle]} )) && ZINIT[bkp-zle]="${functions[zle]}"
functions[zle]=':zinit-tmp-subst-zle "$@";'
builtin return 0
} # ]]]
# FUNCTION: .zinit-tmp-subst-off [[[
# Turn off temporary substituting of functions completely for a given mode ("load", "light",
# "light-b" (i.e. the `trackbinds' mode) or "compdef").
.zinit-tmp-subst-off() {
builtin setopt localoptions noerrreturn noerrexit extendedglob warncreateglobal \
typesetsilent noshortloops unset noaliases
local mode="$1"
# Disable temporary substituting of functions only once.
# Disable temporary substituting of functions only the way it was enabled first.
[[ ${ZINIT[TMP_SUBST]} = inactive || ${ZINIT[TMP_SUBST]} != $mode ]] && return 0
ZINIT[TMP_SUBST]=inactive
if [[ $mode != compdef ]]; then
# 0. Unfunction autoload.
(( ${+ZINIT[bkp-autoload]} )) && functions[autoload]="${ZINIT[bkp-autoload]}" || unfunction autoload
fi
# E. Restore original compdef if it existed.
(( ${+ZINIT[bkp-compdef]} )) && functions[compdef]="${ZINIT[bkp-compdef]}" || unfunction compdef
# Restore the possible source function.
(( ${+ZINIT[bkp-source]} )) && functions[source]="${ZINIT[bkp-source]}" || unfunction source 2>/dev/null
(( ${+ZINIT[bkp-.]} )) && functions[.]="${ZINIT[bkp-.]}" || unfunction . 2> /dev/null
# Light and compdef temporary substituting of functions stops here.
[[ ( $mode = light && ${+ICE[trackbinds]} -eq 0 ) || $mode = compdef ]] && return 0
# Unfunction temporary substituting of functions functions.
# A.
(( ${+ZINIT[bkp-bindkey]} )) && functions[bindkey]="${ZINIT[bkp-bindkey]}" || unfunction bindkey
# When `zinit light -b ...' or when `zinit ice trackbinds ...; zinit light ...'.
[[ $mode = light-b || ( $mode = light && ${+ICE[trackbinds]} -eq 1 ) ]] && return 0
# B.
(( ${+ZINIT[bkp-zstyle]} )) && functions[zstyle]="${ZINIT[bkp-zstyle]}" || unfunction zstyle
# C.
(( ${+ZINIT[bkp-alias]} )) && functions[alias]="${ZINIT[bkp-alias]}" || unfunction alias
# D.
(( ${+ZINIT[bkp-zle]} )) && functions[zle]="${ZINIT[bkp-zle]}" || unfunction zle
return 0
} # ]]]
# FUNCTION: pmodload [[[
# Compatibility with Prezto. Calls can be recursive
(( ${+functions[pmodload]} )) || pmodload() {
local -A ices
(( ${+ICE} )) && ices=( "${(kv)ICE[@]}" teleid '' )
local -A ICE ZINIT_ICE
ICE=( "${(kv)ices[@]}" ) ZINIT_ICE=( "${(kv)ices[@]}" )
while (( $# )); do
ICE[teleid]="PZT::modules/$1${ICE[svn]-/init.zsh}"
ZINIT_ICE[teleid]="PZT::modules/$1${ICE[svn]-/init.zsh}"
if zstyle -t ":prezto:module:$1" loaded 'yes' 'no'; then
shift
continue
else
[[ -z ${ZINIT_SNIPPETS[PZT::modules/$1${ICE[svn]-/init.zsh}]} && -z ${ZINIT_SNIPPETS[https://github.com/sorin-ionescu/prezto/trunk/modules/$1${ICE[svn]-/init.zsh}]} ]] && .zinit-load-snippet PZT::modules/"$1${ICE[svn]-/init.zsh}"
shift
fi
done
} # ]]]
#
# Diff functions.
#
# FUNCTION: .zinit-diff-functions [[[
# Implements detection of newly created functions. Performs
# data gathering, computation is done in *-compute().
#
# $1 - user/plugin (i.e. uspl2 format)
# $2 - command, can be "begin" or "end"
.zinit-diff-functions() {
local uspl2="$1"
local cmd="$2"
[[ $cmd = begin ]] && \
{ [[ -z ${ZINIT[FUNCTIONS_BEFORE__$uspl2]} ]] && \
ZINIT[FUNCTIONS_BEFORE__$uspl2]="${(j: :)${(qk)functions[@]}}"
} || \
ZINIT[FUNCTIONS_AFTER__$uspl2]+=" ${(j: :)${(qk)functions[@]}}"
} # ]]]
# FUNCTION: .zinit-diff-options [[[
# Implements detection of change in option state. Performs
# data gathering, computation is done in *-compute().
#
# $1 - user/plugin (i.e. uspl2 format)
# $2 - command, can be "begin" or "end"
.zinit-diff-options() {
local IFS=" "
[[ $2 = begin ]] && \
{ [[ -z ${ZINIT[OPTIONS_BEFORE__$uspl2]} ]] && \
ZINIT[OPTIONS_BEFORE__$1]="${(kv)options[@]}"
} || \
ZINIT[OPTIONS_AFTER__$1]+=" ${(kv)options[@]}"
} # ]]]
# FUNCTION: .zinit-diff-env [[[
# Implements detection of change in PATH and FPATH.
#
# $1 - user/plugin (i.e. uspl2 format)
# $2 - command, can be "begin" or "end"
.zinit-diff-env() {
typeset -a tmp
local IFS=" "
[[ $2 = begin ]] && {
{ [[ -z ${ZINIT[PATH_BEFORE__$uspl2]} ]] && \
tmp=( "${(q)path[@]}" )
ZINIT[PATH_BEFORE__$1]="${tmp[*]}"
}
{ [[ -z ${ZINIT[FPATH_BEFORE__$uspl2]} ]] && \
tmp=( "${(q)fpath[@]}" )
ZINIT[FPATH_BEFORE__$1]="${tmp[*]}"
}
} || {
tmp=( "${(q)path[@]}" )
ZINIT[PATH_AFTER__$1]+=" ${tmp[*]}"
tmp=( "${(q)fpath[@]}" )
ZINIT[FPATH_AFTER__$1]+=" ${tmp[*]}"
}
} # ]]]
# FUNCTION: .zinit-diff-parameter [[[
# Implements detection of change in any parameter's existence and type.
# Performs data gathering, computation is done in *-compute().
#
# $1 - user/plugin (i.e. uspl2 format)
# $2 - command, can be "begin" or "end"
.zinit-diff-parameter() {
typeset -a tmp
[[ $2 = begin ]] && {
{ [[ -z ${ZINIT[PARAMETERS_BEFORE__$uspl2]} ]] && \
ZINIT[PARAMETERS_BEFORE__$1]="${(j: :)${(qkv)parameters[@]}}"
}
} || {
ZINIT[PARAMETERS_AFTER__$1]+=" ${(j: :)${(qkv)parameters[@]}}"
}
} # ]]]
# FUNCTION: .zinit-diff [[[
# Performs diff actions of all types
.zinit-diff() {
.zinit-diff-functions "$1" "$2"
.zinit-diff-options "$1" "$2"
.zinit-diff-env "$1" "$2"
.zinit-diff-parameter "$1" "$2"
} # ]]]
#
# Utility functions.
#
# FUNCTION: .zinit-get-mtime-into [[[
.zinit-get-mtime-into() {
if (( ZINIT[HAVE_ZSTAT] )) {
local -a arr
{ zstat +mtime -A arr "$1"; } 2>/dev/null
: ${(P)2::="${arr[1]}"}
} else {
{ : ${(P)2::="$(stat -c %Y "$1")"}; } 2>/dev/null
}
} # ]]]
# FUNCTION: .zinit-any-to-user-plugin [[[
# Allows elastic plugin-spec across the code.
#
# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin)
# $2 - plugin (only when $1 - i.e. user - given)
#
# $REPLY - user and plugin
.zinit-any-to-user-plugin() {
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
builtin setopt extendedglob typesetsilent noshortloops rcquotes \
${${${+reply}:#0}:+warncreateglobal}
# Two components given?
# That's a pretty fast track to call this function this way.
if [[ -n $2 ]]; then
2=${~2}
reply=( ${1:-${${(M)2#/}:+%}} ${${${(M)1#%}:+$2}:-${2//---//}} )
return 0
fi
# Is it absolute path?
if [[ $1 = /* ]]; then