-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path:za-eval-atclone-handler
50 lines (45 loc) · 1.86 KB
/
:za-eval-atclone-handler
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
# Copyright (c) 2021-2023 Nicholas Serrano
# License MIT
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
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"
}
#
# eval'' ice – creation of cache file
#
if [[ -n ${ICE[eval]} ]] {
local cachefile output savedcmd
local -i ret=0
[[ -d "$dir" ]] || {
+zinit-message "{info}[{pre}eval{info}] {log-warn}{msg}Unable to find directory for {pid}$id_as{msg}, skipping{…}{rst}"
return $?
}
cachefile="$dir/evalcache.zsh"
@zinit-substitute 'ICE[eval]'
output="$((( ${+ICE[nocd]} == 0 )) && builtin cd -q "$dir"; eval ${ICE[eval]#!})"
ret=$?
if (( ret )) && [[ ${ICE[eval]:0:1} != "!" ]] {
+zinit-message "{info}[{pre}eval{info}] {log-warn}{msg}Output of (\`{cmd}${${ICE[eval]#!}:0:25}{…}{msg}') returned {error}$ret{msg}, disabling cache{…}{rst}"
builtin print '' > "$cachefile"
return 0
} else {
if (( !OPTS[opt_-q,--quiet] )) && [[ $hook != "atinit" ]] {
+zinit-message "{info}[{pre}eval{info}] {msg}Caching output of (\`{cmd}${${ICE[eval]#!}:0:25}{…}{msg}'){rst}"
}
builtin print -r -- "# ${(q)ICE[eval]#!}
# generated with z-a-eval annex
(( ZINIT_Z_A_EVAL_SOURCED )) && return
typeset -i ZINIT_Z_A_EVAL_SOURCED=1" >! "$cachefile"
builtin print -r -- "${output}" >>! "$cachefile"
if [[ ${+ICE[nocompile]} = 0 || ${ICE[nocompile]} = \! ]] {
zcompile -U "$cachefile" || {
+zinit-message "{info}[{pre}eval{info}] {log-warn}{msg}Error compiling cache file, saving broken file to {url}'$dir/evalcache.broken'{msg} and disabling cache{…}{rst}"
command mv "$cachefile" "$dir/evalcache.broken"
builtin print '# An error occured compiling this cache file ' > "$cachefile"
}
}
}
}