-
Notifications
You must be signed in to change notification settings - Fork 1
/
z-a-man.plugin.zsh
63 lines (51 loc) · 2.05 KB
/
z-a-man.plugin.zsh
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
# According to the Zsh Plugin Standard:
# https://github.com/z-shell/zi/wiki/Zsh-Plugin-Standard
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
# https://github.com/z-shell/zi/wiki/Zsh-Plugin-Standard#2-functions-directory
typeset -g ZMAN_REPO_DIR="${0:h}"
typeset -g ZMAN_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/z-a-zman"
# A simple wrapper around `zman' script to avoid altering PATH
zman() {
"$ZMAN_REPO_DIR/zman" "$ZMAN_REPO_DIR" \
"${ZI[PLUGINS_DIR]}" \
"${ZI[SNIPPETS_DIR]}" "$@";
}
autoload -Uz .za-zman-handler
# Prints one of two possible messages during installation
# adding colors to them and preceding with z-a-man preable
zman-inst() {
if [[ "$1" = g ]]; then
print -P -- "\n%F{38}zman annex: \%F{154}Installing %F{220}$2%F{154} gem locally in the z-a-man directory...%f"
else
print -P -- "\n%F{38}zman annex: \%F{154}$2%f"
fi
}
# Check if ronn dependencies are installed
local zman_dep
local -a farray
for zman_dep in hpricot rdiscount mustache asciidoctor; do
farray=( $ZMAN_REPO_DIR/gems/$zman_dep-*(N[1]) )
[[ ! -d ${farray[1]} ]] && \
{ zman-inst g "$zman_dep"; command gem install --no-user-install -i "$ZMAN_REPO_DIR" "$zman_dep"; }
done
if [[ ! -f $ZMAN_REPO_DIR/bin/zsd ]]; then
zman-inst o "Installing zsdoc..."
make -C $ZMAN_REPO_DIR/zsdoc install PREFIX="$ZMAN_REPO_DIR" >/dev/null
fi
unset -f zman-inst
# An empty stub to fill the help handler fields
za-man-help-null-handler() { :; }
# Register atclone hook
@zi-register-annex "z-a-man" hook:atclone-100 \
.za-zman-handler \
za-man-help-null-handler \
"zman''" # register a new ice-mod: zman''
# Register atpull hook
@zi-register-annex "z-a-man" hook:atpull-100 \
.za-zman-handler \
za-man-help-null-handler
# Refresh zsdoc on update of the plugin
@zsh-plugin-run-on-update &>/dev/null 'make &>/dev/null -C $ZMAN_REPO_DIR/zsdoc install PREFIX="$ZMAN_REPO_DIR"'
zstyle ':completion:*:zman:argument-rest:plugins' list-colors '=(#b)(*)/(*)==1;35=1;33'
zstyle ':completion:*:zman:argument-rest:plugins' matcher 'r:|=** l:|=*'