-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·163 lines (121 loc) · 4.3 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env sh
main () {
set -e
set -u
repo='rxrc/zshrc'
zdotdir="${ZDOTDIR:-${XDG_CONFIG_HOME:-$HOME/.config}/zsh}"
zplug_home="${ZPLUG_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/zplug}"
zplug_cache_dir="${ZPLUG_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/zplug}"
if [ "${1:-}" == 'dev' ]; then
dev_mode ${2:-master}
else
install_zshrc
fi
}
install_zshrc () {
echo -e "\033[32m➤ Installing! \033[0m"
command -v zsh >/dev/null 2>&1 \
&& echo -e "\033[32m ✔ Found ❰ Zsh ❱ \033[0m" \
|| {
echo -e "\033[31m ✘ Missing ❰ Zsh ❱ \033[0m"
echo -e "\033[31m✘ Install failed!"
exit 1
}
command -v git >/dev/null 2>&1 \
&& echo -e "\033[32m ✔ Found ❰ Git ❱ \033[0m" \
|| {
echo -e "\033[31m ✘ Missing ❰ Git ❱ \033[0m"
echo -e "\033[31m✘ Install failed!"
exit 1
}
command -v awk >/dev/null 2>&1 \
&& echo -e "\033[32m ✔ Found ❰ AWK ❱ \033[0m" \
|| {
echo -e "\033[31m ✘ Missing ❰ AWK ❱ \033[0m"
echo -e "\033[31m✘ Install failed!"
exit 1
}
if [ -d $zdotdir ]; then
echo -e "\033[32m ✔ Exists ❰ ${zdotdir} ❱ \033[0m"
else
echo -e " ➤ Creating ❰ ${zdotdir} ❱ \033[0m"
mkdir -p $zdotdir
echo -e "\033[32m ✔ Created ❰ ${zdotdir} ❱ \033[0m"
fi
if [ -d $zplug_home ]; then
echo -e "\033[32m ✔ Exists ❰ ${zplug_home} ❱ \033[0m"
else
echo -e " ➤ Creating ❰ ${zplug_home} ❱ \033[0m"
mkdir -p $zplug_home
echo -e "\033[32m ✔ Created ❰ ${zplug_home} ❱ \033[0m"
fi
if [ -d $zplug_cache_dir ]; then
echo -e "\033[32m ✔ Exists ❰ ${zplug_cache_dir} ❱ \033[0m"
else
echo -e " ➤ Creating ❰ ${zplug_cache_dir} ❱ \033[0m"
mkdir -p $zplug_cache_dir
echo -e "\033[32m ✔ Created ❰ ${zplug_cache_dir} ❱ \033[0m"
fi
if [ -e $zplug_home/init.zsh ]; then
echo -e "\033[32m ✔ Found ❰ zplug ❱ \033[0m"
else
echo -e " ➤ Installing ❰ zplug ❱ \033[0m"
env git clone https://github.com/zplug/zplug $zplug_home >/dev/null 2>&1
echo -e "\033[32m ✔ Installed ❰ zplug ❱ \033[0m"
fi
if [ -f $zdotdir/.zshrc ] || [ -h $zdotdir/.zshrc ]; then
zshrc_line=$(head -n 1 $zdotdir/.zshrc)
if [ "$zshrc_line" != "# ${repo}" ]; then
echo -e " ➤ Exists ❰ ${zdotdir}/.zshrc ❱ \033[0m"
mv $zdotdir/.zshrc $zdotdir/.zshrc.preinstall
echo -e "\033[32m ✔ Moved to ❰ ${zdotdir}/.zshrc.preinstall ❱ \033[0m"
else
rm $zdotdir/.zshrc
fi
fi
echo -e " ➤ Installing ❰ ${zdotdir}/.zshrc ❱ \033[0m"
tee $zdotdir/.zshrc >/dev/null <<EOF
# $repo
export ZSHRC_REPO=$repo
export ZDOTDIR="\${ZDOTDIR:-\${XDG_CONFIG_HOME:-\$HOME/.config}/zsh}"
export ZPLUG_HOME="\${ZPLUG_HOME:-\${XDG_CONFIG_HOME:-\$HOME/.config}/zplug}"
export ZPLUG_CACHE_DIR="\${ZPLUG_CACHE_DIR:-\${XDG_CACHE_HOME:-\$HOME/.cache}/zplug}"
zplug_loadfile="\${ZPLUG_HOME}/repos/$repo/packages.zsh"
if [[ -e \$zplug_loadfile ]]; then
export ZPLUG_LOADFILE=\$zplug_loadfile
fi
source "\${ZPLUG_HOME}/init.zsh"
if [[ ! -e \$zplug_loadfile ]]; then
zplug \${ZSHRC_REPO}
zplug install
export ZPLUG_LOADFILE=\$zplug_loadfile
source "\${ZPLUG_HOME}/init.zsh"
fi
zplug \${ZSHRC_REPO}, use:env.zsh
if ! zplug check; then
zplug install
echo '[zplug] Updating cache file: this may take up to a minute'
fi
zplug load
EOF
echo -e "\033[32m ✔ Installed ❰ ${zdotdir}/.zshrc ❱ \033[0m"
echo
echo -e "\033[32m✔ Install complete! \033[0m"
exit 0
}
dev_mode () {
f_str[0]="zplug_loadfile=\"\${ZPLUG_HOME}/repos/${repo}/packages.zsh\""
r_str[0]="zplug_loadfile=\"$(pwd)/packages.zsh\""
f_str[1]="ZSHRC_REPO=${repo}"
r_str[1]="ZSHRC_REPO=\"$(pwd), from:local, at:${1:-master}\""
echo -e "\033[32m➤ Entering development mode! \033[0m"
i=0
while [ $i -lt ${#f_str[@]} ]; do
sed -i -e "s|${f_str[$i]}|${r_str[$i]}|g" $zdotdir/.zshrc
i=$(( i + 1 ))
done
echo -e "\033[32m ✔ New zsh sessions will use zshrc from this directory. \033[0m"
echo -e "\033[32m ➤ Run ./install.sh again to exit development mode. \033[0m"
exit 0
}
main $1 $2