-
Notifications
You must be signed in to change notification settings - Fork 12
/
:za-lb-atdelete-handler
114 lines (99 loc) · 4 KB
/
:za-lb-atdelete-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
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
# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski
# Modified work Copyright (c) 2020-2021 Nicholas Serrano
# License MIT
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops nullglob
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"
}
#
# lbin'' ice – creation of links
#
if (( ${+ICE[lbin]} )) {
(( ${+ICE[sbin]} )) && {
(( !OPTS[opt_-q,--quiet] )) && \
+zinit-message "{pre}linkbin annex: {ice}sbin{warn} ice detected, not doing anything...{rst}"
return;
}
local -a lbins srcdst
lbins=( ${(s.;.)ICE2[lbin]} )
local lbin sym="-P"
(
# CD for the globbing through eval
builtin cd -q "$dir" || return
for lbin ( $lbins "" ) {
[[ ${lbin[1]} = "!" ]] && sym="-s"
if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]] {
local -a files
integer i=0
while [[ ! -f $files[1] && $i -lt 9 ]]; do
((i++))
case $i in
1)
files=( $dir/${id_as:t}(Nnon.) )
;;
2)
[[ -n $plugin ]] && files=( $dir/$plugin(Nnon.) )
;;
3)
[[ -n $url ]] && files=( $dir/${url:t}(Nnon.) )
;;
4)
files=( $dir/*(*Nnon.:t) )
;;
5)
files=( $dir/**/${id_as:t} )
;;
6)
[[ -n $plugin ]] && files=( $dir/**/$plugin(Nnon.) )
;;
7)
[[ -n $url ]] && files=( $dir/**/${url:t}(Nnon.) )
;;
8)
files=( $dir/**/*(*Nnon.:t) )
;;
9)
+zinit-message "{pre}linkbin annex: {error}The automatic-empty {ice}lbin{error} ice didn't find any executable files{rst}"
;;
esac
done
[[ $i -gt 8 ]] && break
lbin=$files[1]
} else {
lbin=${lbin#!}
[[ -z $lbin ]] && continue
}
srcdst=( ${(@s.->.)lbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon.) )"
if (( !${#fnames} )) {
+zinit-message "{pre}linkbin annex: {error}The {ice}lbin{error} ice (\`{glob}$lbin{error}')didn't match any files{rst}"
continue
}
for fname ( $fnames ) {
srcdst[1]="$fname"
local fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ -f $file ]] {
command rm "$file"
if ! [[ -f $file ]]; then
(( !OPTS[opt_-q,--quiet] )) && \
+zinit-message "{pre}linkbin annex: {msg}Removed {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{msg} link{rst}"
else
+zinit-message "{pre}linkbin annex: {error}Something went wrong deleting the {obj}$fnam{error} link{rst}"
fi
} else {
+zinit-message "{pre}linkbin annex: {error}The {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{error} link didn't exist in \$ZPFX/bin (or isn't a regular file){rst}"
}
}
}
)
}
# vim:ft=zsh:sw=4:sts=4:et