Repository navigation
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·176 lines (157 loc) · 7.03 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·176 lines (157 loc) · 7.03 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
#!/bin/zsh
# Set up a Mac. On a new one, from Terminal.app before opening iTerm2:
#
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# git clone https://github.com/pigoz/dotfiles ~/dev/dotfiles
# ~/dev/dotfiles/bootstrap
#
# Safe to run again; `bootstrap links secrets` runs only those steps.
setopt err_exit no_unset pipe_fail
cd ${0:A:h}
step_brew() {
# not installed by default; OrbStack uses it for linux/amd64 images
arch -x86_64 /usr/bin/true 2> /dev/null \
|| sudo softwareupdate --install-rosetta --agree-to-license
[[ -x /opt/homebrew/bin/brew ]] \
|| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew bundle --file=Brewfile
# fontd ignores ~/Library/Fonts if the font casks created it after login
killall -u $USER fontd 2> /dev/null || true
}
link() {
local src=$PWD/$1 dest=$2
[[ -L $dest && $(readlink $dest) == $src ]] && return
mkdir -p -m 700 ${dest:h}
if [[ -e $dest || -L $dest ]]; then
mv $dest $dest.bak
print "backup $dest.bak"
fi
ln -s $src $dest
print "linked $dest"
}
# every top-level entry becomes ~/.<name>; ssh and aws only get their config,
# since those directories also hold keys and caches
step_links() {
local f
for f in *; do
[[ $f == (bootstrap|secrets|README.md|THEME.md|ssh|aws|prefs) ]] && continue
link $f ~/.$f
done
link ssh/config ~/.ssh/config
link aws/config ~/.aws/config
}
step_iterm() {
# iTerm2 writes its in-memory settings back on quit, overwriting these
if [[ -n ${(M)${(f)"$(ps -axo comm=)"}:#*/MacOS/iTerm2} ]]; then
print "iTerm2 is running, skipped: quit it and run \`bootstrap iterm\` from Terminal.app"
return
fi
local domain=com.googlecode.iterm2
defaults write $domain PrefsCustomFolder -string $PWD/config/iterm2
defaults write $domain LoadPrefsFromCustomFolder -bool true
# "Save changes: Automatically"
defaults write $domain NoSyncNeverRemindPrefsChangesLostForFile -bool true
defaults write $domain NoSyncNeverRemindPrefsChangesLostForFile_selection -int 2
print "iTerm2 settings: $PWD/config/iterm2"
}
# keyboard shortcut: id, on|off, then ascii keycode modifiers (optional when off)
hotkey() {
local d="<key>enabled</key><$([[ $2 == on ]] && print true || print false)/>"
if (( $# > 2 )); then
d+="<key>value</key><dict><key>type</key><string>standard</string>"
d+="<key>parameters</key><array><integer>$3</integer><integer>$4</integer><integer>$5</integer></array></dict>"
fi
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add $1 "<dict>$d</dict>"
}
step_macos() {
# ⌃Q Mission Control, ⌃S show desktop, with ⇧ for the slow versions
hotkey 32 on 113 12 262144
hotkey 34 on 113 12 393216
hotkey 36 on 115 1 262144
hotkey 37 on 115 1 393216
# off, keeping their keys: ⌃↓ application windows, ⌃space and ⌃⌥space input sources
hotkey 33 off 65535 125 8650752
hotkey 60 off 32 49 262144
hotkey 61 off 32 49 786432
# off: zoom, contrast and other accessibility keys
local id
for id in 15 16 17 18 19 20 21 22 23 24 25 26 38 40 44 45 46 48 49; do
hotkey $id off
done
defaults write com.apple.dock orientation -string left
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock tilesize -float 39
defaults write com.apple.dock mineffect -string scale
# bottom right hot corner: nothing instead of Quick Note
defaults write com.apple.dock wvous-br-corner -int 1
defaults write com.apple.dock wvous-br-modifier -int 0
defaults write -g AppleInterfaceStyle -string Dark
defaults write -g com.apple.swipescrolldirection -bool false
defaults write -g com.apple.mouse.scaling -float 1.5
defaults write -g AppleLanguages -array en-IT it-IT ja-IT
defaults write -g AppleLocale -string en_IT
defaults write com.apple.finder FXPreferredViewStyle -string clmv
defaults write com.apple.finder NewWindowTarget -string PfHm
defaults write com.apple.finder NewWindowTargetPath -string "file://$HOME/"
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
mkdir -p ~/Screenshots
defaults write com.apple.screencapture location -string '~/Screenshots'
# U.S. keyboard and Japanese (Romaji), plus the system's own input methods
local kotoeri=com.apple.inputmethod.Kotoeri.RomajiTyping
defaults write com.apple.HIToolbox AppleEnabledInputSources -array \
'<dict><key>Bundle ID</key><string>com.apple.CharacterPaletteIM</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>' \
'<dict><key>Bundle ID</key><string>com.apple.PressAndHold</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>' \
'<dict><key>Bundle ID</key><string>com.apple.50onPaletteIM</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>' \
'<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>0</integer><key>KeyboardLayout Name</key><string>U.S.</string></dict>' \
"<dict><key>Bundle ID</key><string>$kotoeri</string><key>Input Mode</key><string>com.apple.inputmethod.Japanese</string><key>InputSourceKind</key><string>Input Mode</string></dict>" \
"<dict><key>Bundle ID</key><string>$kotoeri</string><key>InputSourceKind</key><string>Keyboard Input Method</string></dict>" \
'<dict><key>Bundle ID</key><string>com.apple.inputmethod.ironwood</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>'
# app settings saved by prefs/export (replaces each app's whole domain)
local p
for p in prefs/*.plist; do
defaults import ${p:t:r} $p
print "imported ${p:t:r}"
done
local activate=/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings
[[ -x $activate ]] && $activate -u
killall Dock Finder SystemUIServer 2> /dev/null || true
print "log out and back in for input sources, languages and dark mode"
}
step_mise() {
mise install
}
# one master password prompt for this step and the repos one
step_secrets() {
export BW_SESSION=${BW_SESSION:-$(./secrets session)}
./secrets pull
}
# owner/repo[:dir], cloned into ~/dev; ssh keys come from the secrets step
repos=(
pigoz/home
gromia/backend:gromia-backend
gromia/website:gromia-website
gromia/superagent:superagent
)
step_repos() {
local r dir
for r in $repos; do
dir=~/dev/${r##*[/:]}
[[ -d $dir ]] && continue
GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' \
git clone --recursive git@github.com:${r%%:*}.git $dir
done
# the files that git ignores in those repos (.env, master.key)
./secrets pull
}
step_logins() {
gh auth status > /dev/null 2>&1 || gh auth login
[[ -n $(gcloud auth list --filter=status:ACTIVE --format='value(account)' 2> /dev/null) ]] \
|| gcloud auth login
}
[[ -x /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv zsh)"
for s in ${@:-brew links iterm macos mise secrets repos logins}; do
print -P "\n%B==> $s%b"
step_$s
[[ $s == brew ]] && eval "$(/opt/homebrew/bin/brew shellenv zsh)"
done
print "\nDone."