-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmacsetup
executable file
·288 lines (238 loc) · 7.31 KB
/
macsetup
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
#!/bin/bash
set -o errexit # Exit on most errors (see the manual)
set -o errtrace # Make sure any error trap is inherited
set -o nounset # Disallow expansion of unset variables
set -o pipefail # Use last non-zero exit code in a pipeline
#set -o xtrace # Trace the execution of the script (debug)
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
BREW_PREFIX="/usr/local"
BREW_INSTALLER="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
run_setup() {
SECONDS=0
request_root_privileges
setup_xcode
setup_brew
setup_duti
setup_default_file_associations
install_formulaes_from_brewfile
quit_system_preferences
setup_user_defaults
hide_vendor_directories
show_library_folder
install_pipx
# shellcheck disable=SC2039
echo "✨ Done in $((SECONDS))s."
exit 0
}
log() {
message="$1"
shift
# shellcheck disable=SC2059
printf "$message\n" "$@"
}
get_dotfiles_path() {
fp=$(readlink -f "${0}")
dir=$(dirname "$fp")
cd "$dir" || exit 1
git rev-parse --show-toplevel
}
get_brewfile_path() {
echo "$(get_dotfiles_path)/Brewfile"
}
is_duti_installed() {
if command -v duti >/dev/null; then
return 0
else
return 1
fi
}
install_duti() {
brew install duti
}
setup_duti() {
if ! is_duti_installed; then
log "Installing Duti ..."
install_duti
else
log "Duti is already installed. Skipping ..."
fi
}
install_formulaes_from_brewfile() {
brew update --force
brew bundle --file="$(get_brewfile_path)"
}
is_xcode_command_line_tools_installed() {
if xcode-select -p >/dev/null; then
return 0
else
return 1
fi
}
install_xcode_command_line_tools() {
xcode-select --install >/dev/null
until xcode-select -p >/dev/null; do
sleep 5
done
}
is_xcode_eula_accepted() {
if sudo xcodebuild -license status; then
return 0
else
return 1
fi
}
accept_xcode_eula() {
sudo xcodebuild -license accept
}
setup_xcode() {
if ! is_xcode_command_line_tools_installed; then
log "Installing Xcode Command Line Tools ..."
install_xcode_command_line_tools
else
log "XCode is already installed. Skipping ..."
fi
if ! is_xcode_eula_accepted; then
log "Accepting EULA ..."
accept_xcode_eula
else
log "XCode EULA Already Accepted. Skipping ..."
fi
}
is_brew_installed() {
if command -v brew >/dev/null; then
return 0
else
return 1
fi
}
install_brew() {
curl -fsSL "$BREW_INSTALLER" | bash
export PATH="/opt/homebrew/bin:$PATH"
}
install_pyenv() {
log "Installing pyenv ..."
rm -rf "$HOME/.pyenv"
# shellcheck disable=SC2317
curl -fsS "https://pyenv.run" | bash
}
install_pipx() {
log "Installing pipx ..."
# shellcheck disable=SC2317
brew install pipx
pipx ensurepath
sudo pipx --global ensurepath
pipx completions
}
setup_brew() {
if [ -d "$BREW_PREFIX" ]; then
if ! [ -r "$BREW_PREFIX" ]; then
sudo chown -R "$LOGNAME:admin" "$BREW_PREFIX"
fi
else
sudo mkdir "$BREW_PREFIX"
sudo chflags norestricted "$BREW_PREFIX"
sudo chown -R "$LOGNAME:admin" "$BREW_PREFIX"
fi
if ! is_brew_installed; then
log "Installing Homebrew ..."
install_brew
else
log "Homebrew Already Installed. Skipping ..."
fi
}
request_root_privileges() {
log "Requesting root privileges ..."
sudo -v
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
}
setup_default_file_associations() {
log "Setting preferred default file associations ..."
curl "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml" \
| yq e "to_entries | (map(.value.extensions) | flatten) - [null] | unique | .[]" \
| xargs -L 1 -I "{}" duti -s com.todesktop.230313mzl4w4u92 {} all
}
set_wallpaper() {
log "Setting wallpaper ..."
# osascript -e "
# tell application \"System Events\"
# tell every desktop
# set picture to \"$HOME/github/dotfiles/os/darwin/wallpaper/The Cliffs.heic\"
# end tell
# end tell"
}
quit_system_preferences() {
log "Quitting System Preferences ..."
osascript -e 'tell application "System Preferences" to quit'
}
disable_keypress_itunes() {
# Prevent the keyboard media controls from opening iTunes
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2>/dev/null
}
setup_user_defaults() {
log "Setting up user defaults ..."
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
# Always show expanded save panel
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Always show expanded print panel
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Automatically quit printer app once all jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the "Are you sure you want to open this application?" dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Increase the Bluetooth sound quality
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
# Disable the shadows in screenshots
defaults write com.apple.screencapture disable-shadow -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Disable the file extension change warning
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Use the list view in all Finder windows by default
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Expand the "General", "Open with", and "Sharing & Permissions" in File Info
defaults write com.apple.finder FXInfoPanesExpanded -dict \
General -bool true \
OpenWith -bool true \
Privileges -bool true
# Minimize windows into their application icon
defaults write com.apple.dock minimize-to-application -bool true
# Disable show recent applications in Dock
defaults write com.apple.dock show-recents -bool false
# Start TextEdit in plain-text mode
defaults write com.apple.TextEdit RichText -int 0
# Launch Activity Monitor to main window
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
# Visualize CPU usage in Activity Monitor Dock icon
defaults write com.apple.ActivityMonitor IconType -int 5
# Show all processes in Activity Monitor
defaults write com.apple.ActivityMonitor ShowCategory -int 0
# Sort Activity Monitor results by CPU usage
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
defaults write com.apple.ActivityMonitor SortDirection -int 0
# Set default dock size to 45 pixels
defaults write com.apple.dock "tilesize" -int "45" && killall Dock
# Enable AirDrop over Ethernet
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
}
hide_vendor_directories() {
log "Hiding unused directories ..."
# Show ~/Library folder
chflags nohidden "$(realpath ~/Library)"
# Hide unused app directories
chflags hidden "$HOME/Music"
chflags hidden "$HOME/Movies"
chflags hidden "$HOME/Pictures"
chflags hidden "$HOME/Public"
}
show_library_folder() {
chflags nohidden "$(realpath "$HOME/Library")"
}
run_setup