-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
327 lines (237 loc) · 9.72 KB
/
Copy pathinstall.sh
File metadata and controls
327 lines (237 loc) · 9.72 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/zsh
#############
# Functions #
#############
# This will modify "~/.zshrc", so make sure no one else is using it
function append_OMZ_Plugin_To_zshrc() {
local PLUGIN_NAME="$1"
awk -v my_text="plugins+=(${PLUGIN_NAME})" '
/^plugins\+?=/ { last = NR; }
{ lines[NR] = $0; }
END {
for (i = 1; i <= NR; i++) {
print lines[i];
if (i == last) print my_text;
}
}
' ~/.zshrc > zshrc_temp
mv zshrc_temp ~/.zshrc
}
#
function install_cask_if_required() {
local APP=$1
brew list "${APP}" &>/dev/null || brew install --cask "${APP}";
}
#
function install_if_required() {
local APP=$1
brew list "${APP}" &>/dev/null || brew install "${APP}";
}
###############
# Sudo access #
###############
# First, "Preauthenticate" user to avoid being prompted later on (this won't switch users). Lasts for about 15 mins.
current_user="$(whoami)"
sudo -v
[[ "${current_user}" != "$(whoami)" ]] && exit 1
# Keep-alive: update existing `sudo` time stamp until this script finishes
# https://github.com/mathiasbynens/dotfiles/blob/c886e139233320e29fd882960ba3dd388d57afd7/.macos#L13
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
############
# Homebrew #
############
# `-s` (silent) isn't working, so need to redirect output
if ! which -s brew &>/dev/null; then
echo "Homebrew not found... installing"
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ ! -f ~/.zprofile ]]; then
echo >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
echo '.zprofile already exists'
fi
else
echo 'Homebrew already installed... skipping'
fi
#################
# Dotfiles Repo #
#################
if [[ ! -d ~/Documents/dotfiles ]]; then
echo 'Dotfiles not found... installing'
# We'll be able to `clone` and `pull`, but not `push`. This is ok for now.
git clone https://github.com/LuisGL100/dotfiles.git ~/Documents/dotfiles
else
echo 'Dotfiles detected... skipping'
fi
#######
# Git #
#######
if [[ ! -f ~/.gitconfig ]]; then
echo 'Git config not found... installing'
ln -s ~/Documents/dotfiles/git/gitconfig ~/.gitconfig
else
echo 'Git config detected... skipping'
fi
##############
# Oh-my-zsh! #
##############
if [[ ! -d ~/.oh-my-zsh ]]; then
echo 'Oh-my-zsh not found... installing'
# Needs to be an "unattended" install... otherwise, you'll run into this issue:
# https://stackoverflow.com/questions/68440855/bash-script-exits-early-after-installing-oh-my-zsh
#
# There's still some issue with this command... the Terminal makes a sound when it runs
# Perhaps I should explore a different approach such as:
# https://www.reddit.com/r/zsh/comments/riokz2/comment/hoymdph/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
ln -s ~/Documents/dotfiles/ohmyzsh/my_zshrc.zsh ~/.oh-my-zsh/custom/my_zshrc.zsh
else
echo 'Oh-my-zsh detected... skipping'
fi
#################
# Powerlevel10K #
#################
# First, install and set NerdFont
if ! brew list font-meslo-for-powerlevel10k &>/dev/null; then
echo 'NerdFont Meslo not detected... installing'
brew install --cask font-meslo-for-powerlevel10k
# Script Editor -> File -> Open dictionary... is very useful
# The "set font" command works by itself; however, it doesn't work when run from the script for some reason
# I'm not sure if it's the "activate" or the "delay" that fixes it, but they work
osascript -e "tell application \"Terminal\" to activate" -e "delay 1" -e "tell application \"Terminal\" to set the font name of default settings to \"MesloLGS-NF-Regular\""
else
echo 'NerdFont Meslo detected... skipping'
fi
# Then, install P10K
check_font=$(osascript -e "tell application \"Terminal\" to get the font name of window 1")
if ! brew list powerlevel10k &>/dev/null && [[ "${check_font}" == "MesloLGS-NF-Regular" ]]; then
echo 'P10k not detected... installing'
brew install romkatv/powerlevel10k/powerlevel10k
echo '\n# Added by the mac_setup script' >> ~/.zshrc
echo "source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme" >> ~/.zshrc
# TODO: Now that the "dotfiles" repo is being cloned, we could use the local file instead
# curl -fsSL "https://raw.githubusercontent.com/LuisGL100/dotfiles/refs/heads/main/p10k/p10k.zsh" -o ~/.p10k.zsh
ln -s ~/Documents/dotfiles/p10k/p10k.zsh ~/.p10k.zsh
touch "zshrc_tmp"
>>"zshrc_tmp" print -r -- "# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\" ]]; then
source \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\"
fi
"
>>"zshrc_tmp" print -r -- "$(cat ~/.zshrc)"
>>"zshrc_tmp" print -r -- "
# To customize prompt, run \`p10k configure\` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh"
mv "zshrc_tmp" "${HOME}/.zshrc"
else
echo 'P10k already installed, or NerdFont missing... skipping'
fi
###########################
# Zsh-syntax-highlighting #
###########################
if ! brew list zsh-syntax-highlighting &>/dev/null; then
echo 'zsh-syntax-highlighting not detected... installing'
brew install zsh-syntax-highlighting
echo '\n# Added by the mac_setup script' >> ~/.zshrc
echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
else
echo 'zsh-syntax-highlighting detected... skipping'
fi
#######################
# Zsh-autosuggestions #
#######################
if ! brew list zsh-autosuggestions &>/dev/null; then
echo 'zsh-autosuggestions not detected... installing'
brew install zsh-autosuggestions
echo '\n# Added by the mac_setup script' >> ~/.zshrc
echo "source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
else
echo 'zsh-autosuggestions detected... skipping'
fi
#######
# FZF #
#######
if ! brew list fzf &>/dev/null; then
echo 'fzf not detected... installing'
brew install fzf
echo '\n# Added by the mac_setup script' >> ~/.zshrc
# Single quotes not needed to prevent "process substitution"... this is why:
# https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
# It is also why VS Code doesn't highlight `fzf --zsh` as a command (unlike `brew --prefix` above)
# As further proof... try surrounding the parenthesis with backticks, like so: `(fzf --zsh)`
# and you'll see the syntax highlight work
echo "source <(fzf --zsh)" >> ~/.zshrc
# fzf-tab
git clone https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/fzf-tab
# sed -i "" '/^plugins=(git)$/ s/)$/ fzf-tab zsh-interactive-cd)/' ~/.zshrc
append_OMZ_Plugin_To_zshrc "fzf-tab"
append_OMZ_Plugin_To_zshrc "zsh-interactive-cd"
else
echo 'fzf detected... skipping'
fi
###########
# VS Code #
###########
if ! brew list visual-studio-code &>/dev/null; then
brew install --cask visual-studio-code
mkdir -p ~/Library/Application\ Support/Code/User
ln -s ~/Documents/dotfiles/vscode/keybindings.json ~/Library/Application\ Support/Code/User/keybindings.json
ln -s ~/Documents/dotfiles/vscode/settings.json ~/Library/Application\ Support/Code/User/settings.json
else
echo 'VS Code detected... skipping'
fi
########
# Node #
########
if ! command -v node > /dev/null; then
git clone https://github.com/lukechilds/zsh-nvm ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-nvm
append_OMZ_Plugin_To_zshrc "zsh-nvm"
# Manually `source` nvm this time, so we don't have to quit the Terminal to use it
source "$HOME/.oh-my-zsh/custom/plugins/zsh-nvm/zsh-nvm.plugin.zsh"
nvm install --lts
else
echo "NodeJS detected... skipping"
fi
##########
# iTerm2 #
##########
if ! brew list iterm2 &>/dev/null; then
brew install --cask iterm2
cp ~/Documents/dotfiles/iterm2/iterm2_initial_prefs.plist ~/Library/Preferences/com.googlecode.iterm2.plist
xattr -c ~/Library/Preferences/com.googlecode.iterm2.plist
xattr -c ~/Documents/dotfiles/iterm2/shared_prefs/com.googlecode.iterm2.plist
defaults write com.googlecode.iterm2 LoadPrefsFromCustomFolder -bool true
defaults write com.googlecode.iterm2 PrefsCustomFolder -string "$HOME/Documents/dotfiles/iterm2/shared_prefs"
defaults write com.googlecode.iterm2 NoSyncNeverRemindPrefsChangesLostForFile -bool true
defaults write com.googlecode.iterm2 NoSyncNeverRemindPrefsChangesLostForFile_selection -int 2
else
echo 'iTerm2 detected... skipping'
fi
#############
# Utilities #
#############
install_cask_if_required fork
############
# Defaults #
############
# If entry doesn't exist, `Set` will give an error; likewise, `Add` will error if entry exists.
# On a new machine, this value won't exist.
# Also, it needs to be executed after installing NerdFonts; otherwise, the "AppleScript" part overwrites this
/usr/libexec/PlistBuddy -c 'Add :"Window Settings":Basic:useOptionAsMetaKey bool true' ~/Library/Preferences/com.apple.Terminal.plist
# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
########
# TEMP #
########
echo "\n# Temp" >> ~/.zshrc
echo "alias lz='ls -laFG'" >> ~/.zshrc
echo "alias vsc='open -a /Applications/Visual\ Studio\ Code.app '" >> ~/.zshrc
echo "alias vsrc='open -a /Applications/Visual\ Studio\ Code.app ~/.zshrc'" >> ~/.zshrc
#################
# Kill Terminal #
#################
# This is needed for some changes to take effect
# killall Terminal