/
macos.zsh
executable file
·313 lines (254 loc) · 11.4 KB
/
macos.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/zsh
# This script is heavily inspired by [SukkaW](https://github.com/SukkaW/dotfiles/blob/master/_install/macos.zsh)
# curl -o macos.zsh https://raw.githubusercontent.com/liby/liby/master/scripts/macos.zsh && chmod +x macos.zsh && ./macos.zsh
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "No macOS detected!"
exit 1
fi
start() {
clear
echo "==========================================================="
echo " "
echo "▀█████████▄ ▄████████ ▄██ ▄ ▄████████ ███▄▄▄▄ "
echo " ███ ███ ███ ███ ███ ██▄ ███ ███ ███▀▀▀██▄ "
echo " ███ ███ ███ ███ ███▄▄▄███ ███ ███ ███ ███ "
echo " ▄███▄▄▄██▀ ▄███▄▄▄▄██▀ ▀▀▀▀▀▀███ ███ ███ ███ ███ "
echo "▀▀███▀▀▀██▄ ▀▀███▀▀▀▀▀ ▄██ ███ ▀███████████ ███ ███ "
echo " ███ ██▄ ▀███████████ ███ ███ ███ ███ ███ ███ "
echo " ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ "
echo "▄█████████▀ ███ ███ ▀█████▀ ███ █▀ ▀█ █▀ "
echo " ███ ███ "
echo " "
echo "==========================================================="
echo " !! ATTENTION !! "
echo " YOU ARE SETTING UP: Bryan Environment (macOS) "
echo "==========================================================="
echo " "
echo -n " * The setup will begin in 5 seconds... "
sleep 5
echo -n "Times up! Here we start!"
echo "-----------------------------------------------------------"
cd $HOME
}
is_apple_silicon() {
[[ "$(/usr/bin/uname -m)" == "arm64" ]]
}
brew_shellenv() {
# It will export env variable: HOMEBREW_PREFIX, HOMEBREW_CELLAR, HOMEBREW_REPOSITORY, HOMEBREW_SHELLENV_PREFIX
# It will add path: $PATH, $MANPATH, $INFOPATH
if is_apple_silicon; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
}
install_homebrew() {
echo "==========================================================="
echo " Install Homebrew "
echo "-----------------------------------------------------------"
# xcode command tool will be installed during homebrew installation
xcode-select --install || true
if [ ! -x "$(command -v brew)" ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew_shellenv
if ! ([[ -e ~/.zprofile ]] && grep -q "brew shellenv" ~/.zprofile); then
echo "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" >> "${HOME}/.zprofile"
echo "typeset -U path" >> "${HOME}/.zprofile"
fi
brew analytics off && brew update
echo "Homebrew installed."
else
echo "Homebrew already installed. Skipping..."
fi
}
install_brew_packages() {
# Only install required packages for setting up enviroments
# Later we will call brew bundle
__pkg_to_be_installed=(
curl
git
jq
zsh
)
echo "==========================================================="
echo " * Install following packages: "
echo " "
for __pkg ($__pkg_to_be_installed); do
echo " - ${__pkg}"
done
echo "-----------------------------------------------------------"
brew update
for __pkg in $__pkg_to_be_installed; do
if brew list --formula | grep -q "^${__pkg}\$"; then
echo "${__pkg} is already installed, skipping..."
else
brew install ${__pkg} || true
fi
done
}
brew_bundle() {
echo "-----------------------------------------------------------"
echo " * Restore bundles from Homebrew "
echo "-----------------------------------------------------------"
brew bundle
}
setup_ohmyzsh() {
echo "==========================================================="
echo " Shells Enviroment "
echo "-----------------------------------------------------------"
echo " * Installing Oh My Zsh... "
echo "-----------------------------------------------------------"
if [[ -d "$HOME/.oh-my-zsh" ]]; then
echo "Oh My Zsh is already installed, skipping..."
else
echo "Oh My Zsh is not installed, proceeding with the installation..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
echo "-----------------------------------------------------------"
echo " * Installing ZSH Custom Plugins & Themes: "
echo " "
echo " - zsh-autosuggestions "
echo " - zsh-completions "
echo " - fast-syntax-highlighting "
echo " "
echo "-----------------------------------------------------------"
export ZSH_PLUGINS_PREFIX="$HOME/.zsh/plugins"
[[ ! -d "$ZSH_PLUGINS_PREFIX" ]] && mkdir -p $ZSH_PLUGINS_PREFIX
if [[ ! -d "${ZSH_PLUGINS_PREFIX}/zsh-autosuggestions" ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_PLUGINS_PREFIX}/zsh-autosuggestions
fi
if [[ ! -d "${ZSH_PLUGINS_PREFIX}/zsh-completions" ]]; then
git clone https://github.com/zsh-users/zsh-completions ${ZSH_PLUGINS_PREFIX}/zsh-completions
fi
if [[ ! -d "${ZSH_PLUGINS_PREFIX}/fsh" ]]; then
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_PLUGINS_PREFIX}/fsh
fi
}
install_starship() {
echo "==========================================================="
echo " Install Starship "
echo "-----------------------------------------------------------"
if command -v starship > /dev/null; then
echo "Starship is already installed, skipping..."
else
curl -sS https://starship.rs/install.sh | sh
fi
}
restore_dotfiles() {
echo "-----------------------------------------------------------"
echo " * Restore Bryan/dotfiles from GitHub.com "
echo "-----------------------------------------------------------"
if [[ -d "$HOME/.dotfiles" ]]; then
echo "Dotfiles already restored, skipping..."
else
git clone --bare git@github.com:liby/dotfiles.git $HOME/.dotfiles
alias dot="git --git-dir=$HOME/.dotfiles --work-tree=$HOME"
dot config --local status.showUntrackedFiles no
dot checkout --force
brew_bundle
fi
}
install_nodejs() {
echo "==========================================================="
echo " Setting up NodeJS Environment "
echo "==========================================================="
if command -v n > /dev/null; then
echo "tj/n is already installed, skipping..."
return
fi
export N_PREFIX="$HOME/.n"
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s lts
# Set NPM Global Path
export NPM_CONFIG_PREFIX="$HOME/.npm-global"
# Create .npm-global folder if not exists
[[ ! -d "$NPM_CONFIG_PREFIX" ]] && mkdir -p $NPM_CONFIG_PREFIX
echo "-----------------------------------------------------------"
echo " * Installing Node.js LTS... "
echo "-----------------------------------------------------------"
n lts
echo "-----------------------------------------------------------"
echo -n " * Node.js Version: "
node -v
echo "-----------------------------------------------------------"
__npm_global_pkgs=(
@upimg/cli
0x
# clinic
npm-why
# serve
# vercel
)
echo "-----------------------------------------------------------"
echo " * npm install global packages: "
echo " "
for __npm_pkg ($__npm_global_pkgs); do
echo " - ${__npm_pkg}"
done
echo "-----------------------------------------------------------"
for __npm_pkg ($__npm_global_pkgs); do
npm i -g ${__npm_pkg}
done
}
install_rust() {
echo "==========================================================="
echo " Install Rust "
echo "-----------------------------------------------------------"
if command -v rustc > /dev/null; then
echo "Rust is already installed, skipping..."
else
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
}
install_font() {
echo "==========================================================="
echo " Install Inconsolata LGC "
echo "-----------------------------------------------------------"
local font_file="$HOME/Downloads/InconsolataLGC.zip"
if [[ -e "${font_file}" ]]; then
echo "Font already downloaded, skipping..."
else
curl -LJO https://github.com/ryanoasis/nerd-fonts/releases/latest/download/InconsolataLGC.zip -o $font_file
fi
}
reload_zshrc() {
echo "==========================================================="
echo " Reload Bryan env zshrc "
echo "-----------------------------------------------------------"
rm ~/.zcompdump*; compinit -i
exec zsh
}
finish() {
echo "==========================================================="
echo "Done! "
echo " "
echo "> Bryan Enviroment Setup finished! "
echo "> Do not forget run those things: "
echo " "
echo "- NPM login "
echo "- Steup iTerm2 "
echo "- Steup launchd for notes "
echo "- Install Bob, "
echo " Slack, "
echo " WeChat, "
echo " Telegram, "
echo " The Unarchiver, "
echo " Hidden Bar "
echo " from the Apple Store "
echo "- Install Inconsolata LGC "
echo "- Create a case-sensitive volume on macOS "
echo "- https://www.v2ex.com/t/813229?p=1#r_11048555 "
echo " "
echo "==========================================================="
cd $HOME
}
start
install_homebrew
install_brew_packages
setup_ohmyzsh
install_starship
restore_dotfiles
install_nodejs
install_rust
install_font
finish
reload_zshrc