-
Notifications
You must be signed in to change notification settings - Fork 4
/
za-rust-atdelete-handler
56 lines (47 loc) · 2.12 KB
/
za-rust-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
# Copyright (c) 2019 Sebastian Gniazdowski
# License MIT
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
[[ "$1" = plugin ]] && \
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" hook="$6" || \
local type="$1" url="$2" id_as="$3" dir="$4" hook="$5"
local nl=$'\n'
if [[ -n "${ICE[cargo]}" ]] {
local -a cargos bin_pkg_dst tmpsdst
cargos=( "${(s.;.)ICE[cargo]}" )
local cargo
for cargo ( $cargos ) {
bin_pkg_dst=( ${(@s.->.)cargo} )
bin_pkg_dst=( "${bin_pkg_dst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
tmpsdst=( ${(@s.<-.)bin_pkg_dst[1]} )
tmpsdst=( "${tmpsdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
if (( ${#tmpsdst} > 1 )); then
bin_pkg_dst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${bin_pkg_dst[2]:-${tmpdist[2]#\!}}" )
else
bin_pkg_dst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${bin_pkg_dst[2]:-${bin_pkg_dst[1]#\!}}" )
fi
bin_pkg_dst=( "${bin_pkg_dst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
if [[ ${bin_pkg_dst[2]} = \!* ]]; then
bin_pkg_dst[2]=${bin_pkg_dst[2]#\!}
bin_pkg_dst[1]=${bin_pkg_dst[1]##[a-zA-Z]##:}
bin_pkg_dst[2]=${bin_pkg_dst[2]##[a-zA-Z]##:}
bin_pkg_dst[3]=${bin_pkg_dst[3]##[a-zA-Z]##:}
else
continue
fi
local target_binary="${${(M)bin_pkg_dst[1]:#/*}:-$dir/bin/${bin_pkg_dst[1]}}" \
fnam="${bin_pkg_dst[3]:-${bin_pkg_dst[1]:t}}"
local file="$ZPFX/bin/$fnam"
if [[ -f $file ]]; then
command rm -f "$file"
if [[ -f $file ]]; then
print -P -- "%F{38}rust annex: %F{160}Couldn't remove the %F{220}$fnam%F{160} shim from \$ZPFX/bin (no write access to \$ZPFX/bin?)%f"
else
print -P -- "%F{38}rust annex: %F{154}Correctly removed the %F{220}$fnam%F{154} shim from \$ZPFX/bin%f" || \
fi
else
print -P -- "%F{38}rust annex: %F{160}The %F{220}$fnam%F{160} shim didn't exist in \$ZPFX/bin (or isn't a regular file)%f"
fi
}
}
# vim:ft=zsh:sw=4:sts=4:et