-
Notifications
You must be signed in to change notification settings - Fork 1
/
.za-zman-handler
112 lines (99 loc) · 4.12 KB
/
.za-zman-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
# Handler for the atclone and atpull hooks
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
if [[ "$1" = plugin ]]; then
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5"
else
local type="$1" url="$2" plugin="" id_as="$3" dir="$4"
fi
local -x GEM_HOME="$ZMAN_REPO_DIR" RUBYLIB="$RUBYLIB:$ZMAN_REPO_DIR/ronn/lib"
local ronn_bin="$ZMAN_REPO_DIR/ronn/bin/ronn"
local -x PATH="$ZMAN_REPO_DIR/bin:$PATH"
integer quiet
if [[ -f ''(#i)$dir/README.md(#qN[1]) && \
( ! -f ''(#i)$dir/README(#qN[1]) || \
''(#i)$dir/README.md(#qN[1]) -nt ''(#i)$dir/README(#qN[1]) )
]]; then
# Message
[[ "${OPTS[opt_-q,--quiet]}" != 1 ]] && {
[[ -f ''(#i)$dir/README(#qN[1]) ]] && \
print -P -- "%F{38}zman annex: %F{154}Updating the manual page for the \
%F{220}${url+$url%F\{154\} snippet}${plugin:+$plugin%F\{154\} plugin}...%f" || \
print -P -- "%F{38}zman annex: %F{154}Generating the manual page for the \
%F{220}${url+$url%F\{154\} snippet}${plugin:+$plugin%F\{154\} plugin}...%f"
}
# Generation
$ronn_bin --roff \
--manual="Manual For \`${url+$url\' Snippet}${plugin:+${plugin##-##}\' Plugin}" \
${user+--organization="$user"} \
(#i)"$dir/README.md"(#qN) 2>/dev/null
else
# Message
[[ "${OPTS[opt_-q,--quiet]}" != 1 ]] && {
if [[ -f ''(#i)$dir/README.md(#qN[1]) ]]; then
print -P -- "%F{38}zman annex: %F{154}Manual page is up to date%f"
else
if [[ ${ZI_ICE[from]} != (gh-r|github-rel) && \
($type != snippet || "$(<$dir/._zinit/mode)" = 1)
]]; then
print -P -- "%F{38}zman annex: %F{154}No README.md in the \
%F{220}${url+$url%F\{154\} snippet}${plugin:+$plugin%F\{154\} plugin}%f"
fi
fi
}
fi
local -a outdated_pths
local pth fname
local -a farray submods
farray=(
$dir/*.plugin.zsh(N) $dir/*.zsh-theme(N)
$dir/*.zsh(N) $dir/init.zsh(N) $dir/*.sh(N)
$dir/*.bash(N) $dir/.zshrc(N)
)
[[ -f $dir/.gitmodules ]] && submods=( ${(@f)"$( grep 'path[[:space:]]*=' $dir/.gitmodules )"} )
submods=( ${submods[@]//(#s)[[:space:]]#path[[:space:]]#=[[:space:]]#/} )
submods=( --exclude-dir=${^submods} )
# Include files with zsh-filetype modelines
farray+=( $dir/${(@f)^"$( builtin cd -q "$dir" && grep -E -rl --exclude-dir=bin --exclude-dir=.git \
--exclude-dir=zsdoc --exclude-dir=.svn ${submods[@]} --binary-files=without-match \
"(#[[:space:]]+vim:.*ft=(sh|bash|zsh)|#[[:space:]]+vim:.*filetype=(sh|bash|zsh)|\
-\*-[[:space:]]+.*[Mm]ode:[[:space:]]*(sh|bash|zsh|ksh|shell-script))" .)"}(N) )
farray=( ${farray[@]:#${dir%/#}/} )
(
builtin cd -q "$dir"
for pth (${(u)farray[@]:P}) {
fname="${pth:t}"
if [[ ! -f $dir/zsdoc/$fname.adoc || \
( $pth -nt $dir/zsdoc/$fname.adoc )
]]; then
outdated_pths+=( "$pth" )
fi
}
if (( ${#outdated_pths} )); then
(
if builtin cd -q "$dir"; then
# Message
[[ "${OPTS[opt_-q,--quiet]}" != 1 ]] && \
print -P -- "%F{38}zman annex: %F{154}Generating code documentation...%f"
local -a dirs
dirs=( "$dir"/*~(*/zsdoc|*/.git|*/.svn|*/.hg|*/.bzr|*/.cvs)(FND) )
# Generation
zsd --fpath "$dir:${(j.:.)dirs}" \
-r --scomm --cignore '(\#*FUN(C|CTION|):*{{{*|[[:blank:]]#\#[[:blank:]]#}}}*|\
[[:blank:]]#\###[[:blank:]]##vim:*|[[:blank:]]#\#[[:blank:]]#-\*-[[:blank:]]##Mode:*)' \
${outdated_pths[@]}
asciidoctor -b manpage zsdoc/${^outdated_pths[@]:t}.adoc 2>/dev/null
fi
)
else
if (( ${#farray} )); then
[[ "${OPTS[opt_-q,--quiet]}" != 1 ]] && \
print -P -- "%F{38}zman annex: %F{154}Code documentation is up to date%f"
else
[[ "${OPTS[opt_-q,--quiet]}" != 1 ]] && \
if [[ ${ZI_ICE[from]} != (gh-r|github-rel) ]]; then
print -P -- "%F{38}zman annex: %F{154}No files with code found%f"
fi
fi
fi
)