-
Notifications
You must be signed in to change notification settings - Fork 9
/
update
executable file
·419 lines (328 loc) · 15.2 KB
/
update
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/usr/bin/env bash
# Symlinks and copies files from the ~/.dotfiles directory into their
# correct locations: $HOME, $HOME/.config/fish, $HOME/.config/templates,
# etc.
# Echoes, then runs the command.
#
# Combines/is inspired by:
#
# http://stackoverflow.com/q/12231792/11543
# https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash
# http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1321001720427#c4751431215627296974
function x {
#echo "$" "$@"
eval "$(printf '%q ' "$@")"
}
# Ensure directory exists
function xmkdir {
if [ ! -d "$1" ]; then
x mkdir -p "$1"
fi
}
# Returns success if found
function exists {
type -P "$1" > /dev/null
}
function heading {
printf '# %s\n' "$@"
}
# SRCDIR is the root of the git repo
# From http://stackoverflow.com/a/246128/11543
SRCDIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# DSTDIR is probably $HOME
if [ -d "$1" ]; then
DSTDIR="$1"
else
DSTDIR="$( cd -P "$( dirname "${SRCDIR}" )" && pwd )"
fi
# "dotfiles" that will end up in $HOME
for f in "$SRCDIR"/home/.* ; do
if [ -d "$f" ]; then
continue
fi
if [ "$(basename "$f")" = ".DS_Store" ]; then
continue
fi
if [ ! -L "$DSTDIR/$(basename "$f")" ]; then
x ln -sf "$f" "$DSTDIR"
fi
done
# Remove dangling symlinks
for f in "$DSTDIR"/.* ; do
if readlink "$f" > /dev/null ; then
if [ ! -f "$(readlink "$f")" ]; then
x rm "$f"
fi
fi
done
# Set PLATFORM after $HOME/.platform has been symlinked
PLATFORM=$("$HOME"/.platform)
# Ask for sudo upfront if we're likely to need it
if [ "$PLATFORM" = "linux" ]; then
export DEBIAN_FRONTEND="noninteractive"
# Good for 5 mins; for more see https://github.com/mathiasbynens/dotfiles/blob/master/.macos#L13
sudo -v > /dev/null
SUDO=$? # no boolean values in bash; use [ $SUDO -ne 1 ] in expressions
fi
LOCAL="$HOME/local"
xmkdir "$LOCAL"
BINDIR="$LOCAL/bin"
xmkdir "$BINDIR"
case "$PLATFORM" in
darwin )
heading "macos"
# For some reason *some* applications (like TextEdit) won't read
# DefaultKeyBinding.dict if it's symlinked, or is in a symlinked directory,
# so rsync instead of symlink... http://apple.stackexchange.com/a/53110/890
# rdar://12429092
x rsync -a --delete "$SRCDIR/etc/KeyBindings" "$DSTDIR/Library"
# https://github.com/mathiasbynens/dotfiles/blob/master/.macos
# https://github.com/hjuutilainen/dotfiles/blob/master/bin/osx-user-defaults.sh
# https://github.com/ymendel/dotfiles/tree/master/osx
# https://github.com/drduh/OS-X-Security-and-Privacy-Guide
# How to figure out the bundle identifier of an app:
#
# osascript -e 'id of app "Safari"'
# => com.apple.Safari
# How to figure out what setting to change (for fish shell):
#
# vimdiff (defaults read -g | psub) (read -p "echo 'Make change and press enter (:qa to exit vimdiff!) > '" ; and defaults read -g | psub)
# vimdiff (defaults read pro.writer.mac | psub) (read -p "echo 'Make change and press enter (:qa to exit vimdiff!) > '" ; and defaults read pro.writer.mac | psub)
# System: disable smart quotes
x defaults write -g NSAutomaticQuoteSubstitutionEnabled -bool false
# System: disable smart dashes
x defaults write -g NSAutomaticDashSubstitutionEnabled -bool false
# System: don't correct spelling automatically
x defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
x defaults write -g WebAutomaticSpellingCorrectionEnabled -bool false
# System: don't capitalize words automatically
x defaults write -g NSAutomaticCapitalizationEnabled -bool false
# System: don't convert double space to period + double space
x defaults write -g NSAutomaticPeriodSubstitutionEnabled -bool false
# System: don't show suggestions on the Touch Bar!
x defaults write -g NSAutomaticTextCompletionEnabled -bool false
# System: don't default to iCloud
x defaults write -g NSDocumentSaveNewDocumentsToCloud -bool false
# System: speed up mouse (requires logout to take effect?)
x defaults write -g com.apple.mouse.scaling -float 6
# System: enable right click
x defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode -string TwoButton
# System: show all extensions (really Finder?)
x defaults write -g AppleShowAllExtensions -int 1
# Finder: keep folders on top when sorting by name
x defaults write com.apple.finder _FXSortFoldersFirst -int 1
# Finder: show status bar
x defaults write com.apple.finder ShowStatusBar -bool true
# Finder: disable the warning when changing a file extension
x defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Finder: new finder window shows home
x defaults write com.apple.finder NewWindowTarget -string PfHm
# Terminal: disable "marks" http://apple.stackexchange.com/a/209907/890
x defaults write com.apple.Terminal AutoMarkPromptLines -int 0
# Safari: show the full URL in the address bar (note: this still hides the scheme)
#x defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
# Safari: enable debug menu
#x defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
# Safari: enable develop menu
#x defaults write com.apple.Safari IncludeDevelopMenu -bool true
# Safari: show status bar
#x defaults write com.apple.Safari ShowStatusBar -bool true
# Photos: don't open automatically when external media is connected
x defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
# Messages: no automatic emoji
x defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticEmojiSubstitutionEnablediMessage" -bool false
# Messages: no smart quotes
x defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticQuoteSubstitutionEnabled" -bool false
# Messages: no smart dashes
x defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticDashSubstitutionEnabled" -bool false
# Messages: no automatic spell correction
x defaults write com.apple.messageshelper.MessageController SOInputLineSettings -dict-add "automaticSpellingCorrectionEnabled" -bool false
# Spotlight: configure categories
# defaults read com.apple.Spotlight orderedItems | sed -E -e 's/^[[:space:]]+//g' | tr -d '()\n' | tr ',' '\n' | awk -F "\n" '{ print "\'" $1 "\' \\\" }'
x defaults write com.apple.Spotlight orderedItems -array \
'{enabled = 1;name = APPLICATIONS;}' \
'{enabled = 0;name = "MENU_SPOTLIGHT_SUGGESTIONS";}' \
'{enabled = 1;name = "MENU_CONVERSION";}' \
'{enabled = 1;name = "MENU_EXPRESSION";}' \
'{enabled = 1;name = "MENU_DEFINITION";}' \
'{enabled = 1;name = "SYSTEM_PREFS";}' \
'{enabled = 0;name = DOCUMENTS;}' \
'{enabled = 0;name = DIRECTORIES;}' \
'{enabled = 0;name = PRESENTATIONS;}' \
'{enabled = 0;name = SPREADSHEETS;}' \
'{enabled = 0;name = PDF;}' \
'{enabled = 0;name = MESSAGES;}' \
'{enabled = 1;name = CONTACT;}' \
'{enabled = 0;name = "EVENT_TODO";}' \
'{enabled = 0;name = IMAGES;}' \
'{enabled = 0;name = BOOKMARKS;}' \
'{enabled = 0;name = MUSIC;}' \
'{enabled = 0;name = MOVIES;}' \
'{enabled = 0;name = FONTS;}' \
'{enabled = 0;name = "MENU_OTHER";}' \
'{enabled = 0;name = "MENU_WEBSEARCH";}' \
'{enabled = 0;name = SOURCE;}'
# Adjust keybindings
# NSUserKeyEquivalent modifiers:
#
# Command: @
# Control: ^
# Option: ~
# Shift: $
# Tab: \U21e5 (Unicode code point for ⇥ character)
# System/Global: try to default to "Paste and Match Style" on cmd-v http://apple.stackexchange.com/a/167649/890
x defaults write -g NSUserKeyEquivalents -dict-add "Paste and Match Style" -string "@v"
# iA Writer: bind cmd-n to new file, instead of new file in library
x defaults write pro.writer.mac NSUserKeyEquivalents -dict-add "New" -string "@n"
# iA Writer: change default extension
x defaults write pro.writer.mac "Document Path Extension" -string "md"
# iA Writer: disable night mode
x defaults write pro.writer.mac nightMode -int 0
# ia Writer: indent using spaces
x defaults write pro.writer.mac "Editor Indent Using Spaces" -int 1
# iA Writer: use "Quattro" font
x defaults write pro.writer.mac "Editor Typeface" -int 2
# iA Writer: in preview, don't center headings
x defaults write pro.writer.mac "Preview Center Headings" -int 0
# iA Writer: in preview, apply smart punctuation
x defaults write pro.writer.mac "Markdown Smart Punctuation Enabled" -int 1
# iA Writer: show filename extensions
x defaults write pro.writer.mac "Library Show Extension" -int 1
# iA Writer: configure sidebar
x defaults write pro.writer.mac "Library Shows Search Bar" -int 0
x defaults write pro.writer.mac "Organizer Shows Favorites" -int 0
x defaults write pro.writer.mac "Organizer Shows Hashtags" -int 0
x defaults write pro.writer.mac "Organizer Shows Smart Folders" -int 0
# Firefox, Safari: bind cmd-opt-j to "Web Console", to match Chrome (and muscle memory...)
x defaults write org.mozilla.firefox NSUserKeyEquivalents -dict-add "Web Console" -string "@~j"
#x defaults write com.apple.Safari NSUserKeyEquivalents -dict-add "Show Error Console" -string "@~j"
if [ ! -e "$HOME/iCloud" ] && [ -d "$HOME/Library/Mobile Documents/com~apple~CloudDocs" ]; then
x ln -s "$HOME/Library/Mobile Documents/com~apple~CloudDocs" "$HOME/iCloud"
fi
# https://github.com/altercation/ethanschoonover.com/tree/master/projects/solarized/apple-colorpalette-solarized
if [ ! -f "$DSTDIR/Library/Colors/Solarized.clr" ]; then
x cp "$SRCDIR/etc/Solarized.clr" "$DSTDIR/Library/Colors"
fi
# https://plus.google.com/+RomanNurik/posts/4VwE8RrXsGd
if [ ! -f "$DSTDIR/Library/Colors/Material-Design.clr" ]; then
x cp "$SRCDIR/etc/Material-Design.clr" "$DSTDIR/Library/Colors"
fi
# Let's just assume Services is special and copy instead of symlink...
x rsync -a --delete "$SRCDIR/etc/Services/" "$DSTDIR/Library/Services/"
if [[ -x /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport ]]; then
x ln -sf /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport "$BINDIR"
fi
if [[ -x /Applications/Tailscale.app/Contents/MacOS/Tailscale ]]; then
x ln -sf /Applications/Tailscale.app/Contents/MacOS/Tailscale "$BINDIR/tailscale"
fi
if [[ -x "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" ]]; then
x ln -sf "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" "$BINDIR/code"
fi
;;
esac
# Fonts
if [ ! -L "$HOME/.config/fontconfig" ]; then
heading "fonts"
if [ -d "$HOME/.config/fontconfig" ]; then
x rm -rf "$HOME/.config/fontconfig"
fi
x mkdir -p "$HOME/.config"
x ln -s "$SRCDIR/etc/fontconfig" "$HOME/.config/fontconfig"
fi
# fish
heading "fish"
# Fish configuration needs to be in ~/.config/fish
if [ ! -L "$HOME/.config/fish" ]; then
if [ -d "$HOME/.config/fish" ]; then
x rm -rf "$HOME/.config/fish"
fi
x mkdir -p "$HOME/.config"
x ln -s "$SRCDIR/fish" "$HOME/.config/fish"
fi
# Update completions if completions more than 7 days old
if ! find "$HOME"/.local/share/fish/generated_completions -maxdepth 0 -mtime 7 ; then
x echo fish -c fish_update_completions
fi
# starship
if exists starship ; then
heading "starship"
if [ ! -L "$HOME/.config/starship.toml" ]; then
x rm -rf "$HOME/.config/starship.toml"
x ln -s "$SRCDIR/etc/starship/starship.toml" "$HOME/.config/starship.toml"
fi
fi
# Scripts for $LOCAL/bin
if exists brew ; then
heading "brew"
brew analytics off
(brew update || exit) | grep -v "Already up-to-date." # need to agree to license when xcode updates
# The non-HEAD version is 7 years old...
if ! brew leaves | grep -q jed ; then
x brew install jed --HEAD
fi
expected="fish coreutils dict tig wget direnv entr jq pv prettyping exiftool mtr htop pwgen pidcat shellcheck starship gh"
# These packages have non-standard installation mechanisms (see above)
custom="jed"
# These packages are optional (don't remove if present)
optional="imagemagick graphicsmagick youtube-dl go ffmpeg apktool git composer fzf protobuf bundletool scrcpy git-lfs node llm firebase-cli"
comm -13 <(brew leaves | sort) <(echo "$expected" | tr ' ' '\n' | sort) | xargs -n 1 brew install
comm -23 <(brew leaves | sort) <(echo "$expected" "$custom" "$optional" | tr ' ' '\n' | sort) | xargs -n 1 brew remove
env HOMEBREW_INSTALL_CLEANUP="" brew upgrade
brew cleanup -s # need weirdo env variables and switches because brew...
fi
# apt-get
if exists apt-get && [ "$SUDO" -ne 1 ]; then
heading "apt-get"
x sudo apt-get -y upgrade
expected="apt-file direnv command-not-found dnsutils apache2-utils htop iftop iotop lsof mosh nodejs traceroute mtr-tiny whois sysstat dstat hdparm psmisc locate wget pv zip unzip libxml2-utils jed sqlite3 jq entr roadwarrior"
comm -13 <(dpkg-query -f '${binary:Package}\n' -W | sort) <(echo "$expected" | tr ' ' '\n' | sort) | xargs sudo apt-get -y install
# Can't remove any packages because not possible to determine which were user-installed...
x sudo apt-get -y autoclean
x sudo apt-get -y update
fi
heading "git"
if [ "$PLATFORM" = "darwin" ]; then
git config --file ~/.gitconfig.local credential.helper osxkeychain
fi
heading "vscode"
# Don't use system tools to update VS Code
if [ -e /etc/apt/sources.list.d/vscode.list ] && [ "$SUDO" -ne 1 ]; then
x sudo rm -f /etc/apt/sources.list.d/vscode.list
fi
if ! exists code ; then
if [ -d "/Applications/Visual Studio Code.app" ]; then
x ln -sf "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" "$BINDIR/code"
fi
fi
if exists code ; then
if [ "$PLATFORM" = "linux" ]; then
DST="$DSTDIR/.config/Code/User"
else
DST="$DSTDIR/Library/Application Support/Code/User"
fi
xmkdir "$DST"
for f in "$SRCDIR"/etc/code/* ; do
if [ ! -L "$DST/$(basename "$f")" ]; then
x rm -rf "$DST/$(basename "$f")"
x ln -sf "$f" "$DST"
fi
done
# Let's try Settings Sync for now https://code.visualstudio.com/docs/editor/settings-sync
# expected=$(echo "ms-vscode.vscode-typescript-tslint-plugin golang.go stkb.rewrap esbenp.prettier-vscode eg2.vscode-npm-script GitHub.vscode-pull-request-github DavidAnson.vscode-markdownlint github.github-vscode-theme" | tr '[:upper:]' '[:lower:]')
# actual=$(code --list-extensions | perl -pe '$_ = lc; chomp if eof' | tr '\n' ' ') # perl to remove trailing newline
# # can't use xargs because GNU xargs need -r; macOS xargs does -r by default, but rejects the switch
# for ext in $(comm -23 <(echo "$actual" | tr ' ' '\n' | sort) <(echo "$expected" | tr ' ' '\n' | sort)); do
# code --uninstall-extension "$ext"
# done
# for ext in $(comm -13 <(echo "$actual" | tr ' ' '\n' | sort) <(echo "$expected" | tr ' ' '\n' | sort)); do
# code --install-extension "$ext"
# done
fi
#if exists npm ; then
#
# heading "npm"
#
# # assuming "update" works on first install as well
# ( cd "$HOME"/.dotfiles/npm && x npm update --no-audit --no-fund --no-package-lock --global-style --no-update-notifier )
#
#fi