-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·289 lines (246 loc) · 7.89 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
set -e
# Default settings
ALIASES=${ALIASES:-~/.aliases}
REPO=${REPO:-newtonkiragu/aliases}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
TERMINAL_EMULATOR=${TERMINAL_EMULATOR:-""}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
error() {
echo ${RED}"Error: $@"${RESET} >&2
}
setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}
setup_aliases() {
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w
echo "${BLUE}Cloning Aliases...${RESET}"
command_exists git || {
error "git is not installed"
exit 1
}
if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
error "Windows/MSYS Git is not supported on Cygwin"
error "Make sure the Cygwin git package is installed and is first on the \$PATH"
exit 1
fi
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 --branch "$BRANCH" "$REMOTE" "$ALIASES" || {
error "git clone of aliases repo failed"
exit 1
}
echo
echo "${YELLOW}Done...${RESET}"
}
function addbashaliases() {
echo "${BLUE}Setting up aliases...${RESET}"
if [ -f $HOME/.bashrc ]; then
TERMINAL_EMULATOR=${TERMINAL_EMULATOR:-$HOME/.bashrc}
cat >> $HOME/.bashrc << EOT
# tools
for plugin ($tools); do
if is_plugin TERMINAL_EMULATOR $plugin; then
fpath=($ALIASES/tools/$plugin $fpath)
echo "[aliases] plugin '$plugin' not found"
fi
done
# location of bash aliases
if [ -f $HOME/.aliases/.bash_aliases ]; then
source $HOME/.aliases/.bash_aliases
source $HOME/.aliases/custom/.bash_aliases
else
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'please re-install bash aliases from https://github.com/newtonkiragu/aliases'
fi
# aliases tools
tools=(
alias-finder
git
config
)
EOT
echo "${YELLOW}Done...${RESET}"
elif [ -f $HOME/.zshrc ]; then
TERMINAL_EMULATOR=${TERMINAL_EMULATOR:-$HOME/.zshrc}
cat >> $HOME/.zshrc << EOT
# tools
for plugin ($tools); do
if is_plugin TERMINAL_EMULATOR $plugin; then
fpath=($ALIASES/tools/$plugin $fpath)
echo "[aliases] plugin '$plugin' not found"
fi
done
# location of bash aliases
if [ -f $HOME/.aliases/.bash_aliases ]; then
source $HOME/.aliases/.bash_aliases
source $HOME/.aliases/custom/.bash_aliases
else
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'please re-install bash aliases from https://github.com/newtonkiragu/.aliases'
fi
tools=(
alias-finder
git
config
)
EOT
echo "${YELLOW}Done...${RESET}"
elif [ -f $HOME/.bash_profile ]; then
TERMINAL_EMULATOR=${TERMINAL_EMULATOR:-$HOME/.bash_profile}
cat >> $HOME/.bash_profile << EOT
# tools
for plugin ($tools); do
if is_plugin TERMINAL_EMULATOR $plugin; then
fpath=($ALIASES/tools/$plugin $fpath)
echo "[aliases] plugin '$plugin' not found"
fi
done
# location of bash aliases
if [ -f $HOME/.aliases/.bash_aliases ]; then
source $HOME/.aliases/.bash_aliases
source $HOME/.aliases/custom/.bash_aliases
else
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'please re-install bash aliases from https://github.com/newtonkiragu/.aliases'
fi
tools=(
alias-finder
git
config
)
EOT
echo "${YELLOW}Done...${RESET}"
else
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'no terminal emulator has been found! Please contact the developers for more details'
fi
}
function reload() {
echo "${BLUE}Final Touches...${RESET}"
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
echo "${YELLOW}Done...${RESET}"
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'We cool fam, you now have aliases. Please open a new instance of your terminal to start using your aliases.'
elif [ -f $HOME/.zshrc ]; then
source $HOME/.zshrc
echo "${YELLOW}Done...${RESET}"
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'We cool fam, you now have aliases. Please open a new instance of your terminal to start using your aliases.'
elif [ -f $HOME/.bash_profile ]; then
source $HOME/.bash_profile
echo "${YELLOW}Done...${RESET}"
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'We cool fam, you now have aliases. Please open a new instance of your terminal to start using your aliases.'
else
echo '
# # ### # ##### ####### #####
# # # # # # # # # # #
# # # # # # # # #
# # # # # # ##### ##### #####
####### # # ####### # # #
# # # # # # # # # # #
# # ####### ### # # ##### ####### #####
'
echo 'please reload your terminal fam.'
fi
}
main() {
setup_color
if [ -d "$ALIASES" ]; then
cat <<-EOF
${YELLOW}You already have Aliases installed.${RESET}
You'll need to remove '$ALIASES' if you want to reinstall.
EOF
exit 1
fi
setup_aliases
addbashaliases
reload
printf "$GREEN"
echo 'Please run alias to view pre-set aliases.'
printf "$RESET"
}
main "$@"