-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·104 lines (88 loc) · 2.36 KB
/
install.sh
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
#!/bin/sh
#
# AX-ZSH: Alex' Modular ZSH Configuration
# Copyright (c) 2015-2022 Alexander Barton <[email protected]>
#
# Include "ax-common.sh":
ax_common_sourced=
for dir in "$HOME" "$HOME/.ax" /usr/local /opt/ax /usr; do
[ -z "$ax_common_sourced" ] || break
ax_common="${dir}/lib/ax/ax-common.sh"
# shellcheck source=/usr/local/lib/ax/ax-common.sh
[ -r "$ax_common" ] && . "$ax_common"
done
if [ -z "$ax_common_sourced" ]; then
ax_msg() {
shift
echo "$@"
}
fi
unset dir ax_common ax_common_sourced
safe_rm() {
if [ -f "$1" ] && [ ! -L "$1" ]; then
rm -f "$1.bak" || abort
mv -v "$1" "$1.bak" || abort
fi
rm -f "$1" || abort
}
abort() {
ax_msg 2 "Failed to setup AX-ZSH!"
exit 1
}
umask 027
[ -n "$AXZSH" ] || AXZSH="${ZDOTDIR:-$HOME}/.axzsh"
export AXZSH
S=$(dirname "$0")
if [ "$S" = "$AXZSH" ] || [ "$PWD" = "$AXZSH" ] || [ -L "$AXZSH" ]; then
ax_msg 1 "Initializing \"$AXZSH\":"
else
ax_msg 1 "Install AX-ZSH into \"$AXZSH\":"
mkdir -p "$AXZSH" || abort
ax_msg - "Copying binaries and scripts ..."
cp -pRv "$S/ax.zsh"* "$AXZSH/" || abort
mkdir -p "$AXZSH/bin" || abort
cp -pRv "$S/bin/"* "$AXZSH/bin/" || abort
for f in AUTHORS LICENSE.md README.md; do
cp -pRv "$S/$f" "$AXZSH/" || abort
done
ax_msg - "Copying plugins ..."
for plugin_type in core default_plugins plugins; do
mkdir -p "$AXZSH/$plugin_type" || abort
for p in "$S/$plugin_type/"*; do
echo "$p -> $AXZSH/$p"
rm -fr "${AXZSH:?}/$p" || abort
cp -pR "$S/$p" "$AXZSH/$p" || abort
done
done
ax_msg - "Copying themes ..."
mkdir -p "$AXZSH/themes" || abort
for p in "$S/themes/"*; do
echo "$p -> $AXZSH/$p"
rm -fr "${AXZSH:?}/$p" || abort
cp -pR "$S/$p" "$AXZSH/$p" || abort
done
fi
mkdir -p "$AXZSH/custom_plugins" || abort
mkdir -p "$AXZSH/custom_themes" || abort
ax_msg - "Linking ZSH startup files ..."
for f in \
${ZDOTDIR:-$HOME}/.zlogin \
${ZDOTDIR:-$HOME}/.zlogout \
${ZDOTDIR:-$HOME}/.zprofile \
${ZDOTDIR:-$HOME}/.zshrc \
; do
safe_rm "$f" || abort
ln -sv "$AXZSH/ax.zsh" "$f" || abort
done
if [ ! -d "$AXZSH/active_plugins" ]; then
ax_msg - "Initializing plugin directory \"$AXZSH/active_plugins\" ..."
if command -v zsh >/dev/null; then
zsh "$AXZSH/bin/axzshctl" reset-plugins || abort
else
ax_msg 1 "Oops, \"zsh\" not found!?"
exit 1
fi
else
ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."
fi
ax_msg 0 "AX-ZSH setup successfully."