forked from NICHOLAS85/z-a-linkbin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path:za-lb-atdelete-handler
89 lines (85 loc) · 3.65 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
#!/usr/bin/env zsh
#
# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski
# Modified work Copyright (c) 2020-2021 Nicholas Serrano
# Modified work Copyright (c) 2022 zdharma-continuum and contributors
emulate -LR zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
if [[ "$1" = plugin ]]; then
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"
fi
if (( ${+ICE[lbin]} )); then
# if (( ${+ICE[sbin]} || ${+ZINIT_ICE[sbin]} )); then
# +zi-log "{m} {b}linkbin{rst}: {ice}sbin{rst} ice detected, not doing anything"
# return
# fi
if (( ${+ICE[sbin]} )); then
+zi-log "{m} {b}linkbin{rst}: {ice}sbin{rst} ice detected, not doing anything"
return 0
fi
local -a lbins srcdst
lbins=(${(s.;.)ICE2[lbin]})
local lbin sym="-P"
(
builtin cd -q "$dir" || return
for lbin in $lbins ""; do
[[ ${lbin[1]} = "!" ]] && sym="-s"
if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]]; then
local -a files
integer i=0
while [[ ! -f $files[1] && $i -lt 10 ]]; 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/**/*(*Nnon.:t)) ;;
(6) files=($dir/**/${id_as:t}(Nnon.)) ;;
(7) [[ -n $plugin ]] && files=($dir/**/$plugin(Nnon.)) ;;
(8) [[ -n $url ]] && files=($dir/**/${url:t}(Nnon.)) ;;
(9) files=($dir/**/*(*Nnon.:t)) ;;
(10) +zi-log "{e} {b}linkbin{rst}: {ice}lbin{rst} ice did not detect any executable files" ;;
esac
done
[[ $i -gt 9 ]] && break
lbin=$files[1]
else
lbin=${lbin#!}
[[ -z $lbin ]] && continue
fi
srcdst=(${(@s.->.)lbin})
srcdst=("${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}")
@zinit-substitute "srcdst[1]" "srcdst[2]"
local -a fnames
local fname
if [[ ${srcdst[1]} != /* ]]; then
eval "fnames=(**/${srcdst[1]}(Nnon-.))"
else
eval "fnames=(${srcdst[1]}(Nnon-.))"
fi
if (( !${#fnames} )); then
+zi-log "{e} {b}linkbin{rst}: The {ice}lbin{rst} ice ({glob}$lbin{rst}) did not match any files"
continue
fi
for fname in $fnames; do
srcdst[1]="$fname"
local fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ -f $file ]]; then
command rm "$file"
if ! [[ -f $file ]]; then
(( !OPTS[opt_-q,--quiet] )) && +zi-log "{m} {b}linkbin{rst}: Deleted {file}$fnam{rst} ${${${sym#-P}:+soft}:-hard} link"
else
+zi-log "{e} {b}linkbin{rst}: Failed to delete {file}$fnam{rst} link"
fi
else
+zi-log "{w} {b}linkbin{rst}: {file}$fnam{rst} ${${${sym#-P}:+soft}:-hard} link not found in \$ZPFX/bin"
fi
done
done
)
fi
# vim: set expandtab filetype=zsh shiftwidth=4 softtabstop=4 tabstop=4: