-
Notifications
You must be signed in to change notification settings - Fork 0
/
→za-bgn-shim-list
144 lines (125 loc) · 4.28 KB
/
→za-bgn-shim-list
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
# -*- mode: sh; sh-indentation: 4; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
# Copyright 2020 Sebastian Gniazdowski
# License: MIT
# Synopsis:
# zinit shim-list [-t|--this-dir] [-c|--cat] [-i|--from-ices] \
# [-o|--one-line] [-s|--short]
#
→za-bgn-shim-list() {
emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent \
no_short_loops rc_quotes
autoload is-at-least
local is_58
is-at-least 5.8 && is_58=1
local -a opt_help opt_this_dir opt_cat opt_from_ices opt_one_line \
opt_short
zparseopts -D -E ${is_58:+-F} \
h=opt_help -help=opt_help \
t=opt_this_dir -this-dir=opt_this_dir \
c=opt_cat -cat=opt_cat \
i=opt_from_ices -from-ices=opt_from_ices \
s=opt_short -short=opt_short \
o=opt_one_line -one-line=opt_one_line || \
{
print -Pr "$ZINIT[col-error]Error:$ZINIT[col-msg2]" \
"Incorrect options given to" \
"$ZINIT[col-obj]shim-list$ZINIT[col-msg2], try" \
"$ZINIT[col-obj]--help%f"
return 1
}
(( ${#opt_help} )) && {
print -P "$ZINIT[col-obj]Usage:%f\n" \
"zinit shim-list [-h/--help] [-t|--this-dir] [-i|--from-ices] \\\\\n" \
" [-o|--one-line] [-s|--short] [-c|--cat]"
cat <<END
- -h/--help – shows this message,
- -t/--this-dir – instructs Zinit to look for shims in the current
directory instead of $ZPFX/bin,
- -i/--from-ices – normally the code looks for the shim files by examining
their contents (shims created by BGN annex have a fixed
structure); this option instructs Zinit to show the list of
shims that results from the sbin'' ice of the loaded
plugins; i.e.: if a plugin has sbin'git-open', for example,
then this means that there has to be such shim already
created,
- -o/--one-line – display the list of shim files without line breaks, in
single line, after spaces,
- -s/--short – don't show the plugin/snippet that the shim belongs to,
- -c/--cat – displays contents of each of the found shim
(unimplemented yet).
END
return 0
}
(( !${+functions[.zinit-any-colorify-as-uspl2]} )) && \
builtin source $ZINIT[BIN_DIR]/zinit-side.zsh
if (( !${#opt_from_ices} )) {
local nl=$'\n' brace='{' quote='"'
local pattern='(#s)\#!/usr/bin/env zsh
function * {
local bindir="'
local -a cands
cands=( ${${opt_this_dir:+.}:-$ZPFX/bin}/*(.-NDL-1000) )
cands=( ${cands:#.} )
local rempat="(${ZINIT[PLUGINS_DIR]}|${ZINIT[SNIPPETS_DIR]}"
rempat+="|${ZINIT[PLUGINS_DIR]/.zinit/.zplugin}"
rempat+="|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})"
local snippat="(${ZINIT[SNIPPETS_DIR]}|${ZINIT[SNIPPETS_DIR]/.zinit/.zplugin})/*"
local file
local -a found
integer longest len
for file ( $cands ) {
local body="$(<$file)"
if [[ -n ${body[(r)$pattern]} ]] {
len=${#${file:t}}
(( len > longest )) && longest=len
found+=( $file )
}
}
for file ( $found ) {
local body="$(<$file)" name=$file:t
print -r ${${:-$opt_one_line${(M)${opt_short:-1}:#1}}:+-n} -- ${file:t}" " \
${${(M)${opt_short:-1}:#1}:+${(l:longest+1-${#name}:: :):-}}
if (( !${#opt_short} )) {
if [[ $body = (#b)$~pattern([^$nl]##)$nl* ]] {
local pth=${match[1]%\"}
local id_as=${${${pth##$~rempat}##/##}%\"}
if [[ $pth = $~snippat ]] {
if [[ $id_as = ((OMZ|PZT|PZTM|OMZP|OMZT|OMZL)::|(#i)(http(s|)|ftp(s|)|rsync|ssh)--)* ]] {
{ local url="$(<$pth/._zinit/url)" } 2>/dev/null
} else {
local -A map
map=( -- "/" -EQ- "=" -QM- "?" -AMP- "&" )
local url=${id_as//(#m)(${(~j:|:k)map})/${map[$MATCH]}}
}
print -r "$ZINIT[col-obj]$url$ZINIT[col-rst]"
} else {
(( ${+functions[.zinit-first]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh"
.zinit-any-colorify-as-uspl2 "$id_as"
print -r -- "$REPLY"
}
}
}
}
(( ${#opt_one_line} )) && print
} else {
+zinit-message '[msg2]Listing shims basing on the in-memory ices data...[rst]'
local p
local -A ices
for p ( $ZINIT_REGISTERED_PLUGINS ) {
if [[ -n $ZINIT_SICE[$p] ]] {
ices=( "${(@Q)${(@z)ZINIT_SICE[$p]}}" )
local sbin
local -a sbins
sbins=( ${(s.;.)ices[sbin]} )
if (( ${#sbins} )) {
.zinit-any-colorify-as-uspl2 "$p"
}
for sbin ( $sbins ) {
print "${(r:50:: :)sbin} $REPLY"
}
}
}
}
}
# vim:ft=zsh:sw=4:sts=4:noet: