-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·299 lines (256 loc) · 15.2 KB
/
install
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
#!/bin/bash
DOTFILES_ROOT="$(cd $(dirname $0) && pwd)"
DOTFILES_FILES=(
.profile
.bashrc
.inputrc
.gitconfig
.tmux.conf
.tigrc
.asdfrc
.Brewfile
.ssh/config:ssh_config:600
.ssh/config.d/git:ssh_config_git:600
.config/alacritty/alacritty.toml
.config/git/ignore:git_ignore
.local/bin/get-login-pass.sh::700
)
DOTFILES_FILES_MAC=(.ssh/config.d/agent:ssh_config_agent:600)
VIMRUNTIME_REPO="https://github.com/hrtshu/vimrc.git"
VIMRUNTIME_REPO_SSH="[email protected]:hrtshu/vimrc.git"
VIMRUNTIME_ROOT_DIR=".vim_runtime"
VIMRUNTIME_INSTALLER_FILE="install_awesome_vimrc.sh"
AUTOMATIONS_REPO="https://github.com/hrtshu/automations.git"
AUTOMATIONS_REPO_SSH="[email protected]:hrtshu/automations.git"
AUTOMATIONS_ROOT_DIR="automations"
function ln_ () {
src="$1"
dest="$2"
[ "$src" = "`readlink $dest`" ] && return
ln -i -s "$src" "$dest"
}
function deploy_conf () {
DEST_DIR="$1"
IFS=, ARG=(${2//:/,}) # $2を:で分割して配列に格納
DEST="${ARG[0]}"
SRC="${ARG[1]}"
PERM="${ARG[2]}"
[ -z "$SRC" ] && SRC="$(basename $DEST)"
[ -n "$PERM" ] && chmod "$PERM" "$DOTFILES_ROOT/$SRC"
mkdir -p "$(dirname "$DEST_DIR/$DEST")" && ln_ "$DOTFILES_ROOT/$SRC" "$DEST_DIR/$DEST"
}
if [ -z "${BASH_SOURCE}" ]; then
echo "Please execute with bash" 1>&2
return 1
fi
if [ "${BASH_SOURCE}" != "$0" ]; then
echo "Don't use . (dot) and source command. Please execute as script." 1>&2
return 1
fi
if [ $# -ge 2 ]; then
echo "Usage: $0 [dest_home_dir]" 1>&2
exit 1
fi
DEST_HOME="$1"
[ -z "$DEST_HOME" ] && DEST_HOME=~
if [ ! -d "$DEST_HOME" ]; then
echo "No such directory: $DEST_HOME" 1>&2
exit 1
fi
#### directories #####
mkdir -p "$DEST_HOME/repos"
mkdir -p "$DEST_HOME/tmp"
mkdir -p "$DEST_HOME/.local/bin"
##### dotfiles & config #####
for file in "${DOTFILES_FILES[@]}"; do
deploy_conf "$DEST_HOME" "$file"
done
if [[ "$OSTYPE" == "darwin"* ]]; then
for file in "${DOTFILES_FILES_MAC[@]}"; do
deploy_conf "$DEST_HOME" "$file"
done
fi
##### SSH #####
if [ ! -f "$DEST_HOME/.ssh/id_ed25519" ]; then
mkdir -p "$DEST_HOME/.ssh"
ssh-keygen -t ed25519 -f "$DEST_HOME/.ssh/id_ed25519" -N ""
echo set the ssh key: https://github.com/settings/keys
fi
##### vim #####
VIMRUNTIME_ROOT="$DEST_HOME/$VIMRUNTIME_ROOT_DIR"
VIMRUNTIME_INSTALLER="$VIMRUNTIME_ROOT/$VIMRUNTIME_INSTALLER_FILE"
if [ ! -e "$VIMRUNTIME_ROOT" ]; then
if command -v git > /dev/null; then
git clone --depth=1 "$VIMRUNTIME_REPO" "$VIMRUNTIME_ROOT"
git -C "$VIMRUNTIME_ROOT" remote set-url --push origin "$VIMRUNTIME_REPO_SSH"
. "$VIMRUNTIME_INSTALLER"
else
echo "vimrc installation was skipped (git is not installed)." 1>&2
fi
fi
##### Mac System #####
if [[ "$OSTYPE" == "darwin"* ]]; then
defaults write -g AppleSpacesSwitchOnActivate -int 0 # アプリケーションの切り替えで、アプリケーションのウインドウが開いている操作スペースに移動
defaults write -g _HIHideMenuBar -int 1
defaults write -g TISRomanSwitchState -int 1 # IME switching by caps lock key
# Trackpad
defaults write -g AppleEnableSwipeNavigateWithScrolls -int 0 # swipe to go back / forward in browser
defaults write -g com.apple.trackpad.scaling -string 1.5 # trackpad speed
defaults write -g com.apple.trackpad.scrolling -string 0.5881999999999999 # scroll speed
# Dock
defaults write com.apple.dock autohide -int 1
defaults write com.apple.dock show-recents -int 0
defaults write com.apple.dock tilesize -int 80
## ホットコーナー
defaults write com.apple.dock wvous-br-corner -int 1;
defaults write com.apple.dock wvous-br-modifier -int 0;
# osascript -e 'quit app "Dock"'
# menubar
defaults write com.apple.menuextra.clock ShowSeconds -int 1
## hide spotlight icon
defaults read com.apple.Spotlight "NSStatusItem Visible Item-0" > /dev/null 2>&1 && defaults delete com.apple.Spotlight "NSStatusItem Visible Item-0"
defaults -currentHost write com.apple.Spotlight MenuItemHidden -int 1
## icons
defaults write com.apple.controlcenter "NSStatusItem Visible Bluetooth" -int 1
defaults -currentHost write com.apple.controlcenter Bluetooth -int 2
# desktop
defaults write com.apple.WindowManager EnableStandardClickToShowDesktop -int 0
defaults write com.apple.WindowManager StandardHideDesktopIcons -int 1
# shortcut key
## mission control (option + tab)
## ref: https://ottan.jp/posts/2016/07/system-preferences-terminal-defaults-mission-control#mission-control
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 32 "<dict><key>enabled</key><true/><key>value</key><dict><key>type</key><string>standard</string><key>parameters</key><array><integer>65535</integer><integer>48</integer><integer>524288</integer></array></dict></dict>"
defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 34 "<dict><key>enabled</key><true/><key>value</key><dict><key>type</key><string>standard</string><key>parameters</key><array><integer>65535</integer><integer>48</integer><integer>655360</integer></array></dict></dict>"
# screenshot
mkdir -p ~/Pictures/Screenshots
defaults write com.apple.screencapture location '~/Pictures/Screenshots'
defaults write com.apple.screencapture location-last '~/Pictures/Screenshots'
# startup
nvram StartupMute | grep -q %01 || ( echo changing startup sound to mute; sudo nvram StartupMute=%01 )
# Safari
defaults write com.apple.Safari.SandboxBroker ShowDevelopMenu -int 1
fi
##### misc #####
[ "$DEST_HOME" == "$HOME" ] && command -v xdg-user-dirs-update > /dev/null && xdg-user-dirs-update
[[ "$(git -C "$DOTFILES_ROOT" remote get-url origin)" == "https://github.com/hrtshu/dotfiles"* ]] && git -C "$DOTFILES_ROOT" remote set-url origin "[email protected]:hrtshu/dotfiles.git"
if [ ! -f "$DEST_HOME/.profile_env" ]; then
cat >> "$DEST_HOME/.profile_env" <<EOF
# 環境依存であることが自明な設定だけを追加しましょう
# (例: トークンの設定 export BUNDLE_GITHUB__COM=x-access-token:xxxxxx )
EOF
fi
##### brew #####
if [[ "$OSTYPE" == "darwin"* ]] && ! command -v brew > /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if command -v brew > /dev/null; then
# analytics
brew analytics off
# install packages
brew bundle check -q --no-upgrade --file="$DEST_HOME/.Brewfile" > /dev/null || brew bundle install --no-upgrade --file="$DEST_HOME/.Brewfile"
# autoupdate
brew install -q zenity terminal-notifier # ensure installed
brew autoupdate delete
brew autoupdate start --upgrade --immediate
# TODO: get-login-pass.sh を automations に移行する
sed -i'' -e \
"s|^export PATH=|export SUDO_ASKPASS='$DEST_HOME/.local/bin/get-login-pass.sh'\nexport PATH=|" \
"$DEST_HOME/Library/Application Support/com.github.domt4.homebrew-autoupdate/brew_autoupdate"
fi
##### asdf #####
if command -v brew > /dev/null; then
ASDF="$(brew --prefix)/bin/asdf"
"$ASDF" plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git > /dev/null
"$ASDF" plugin add ruby https://github.com/asdf-vm/asdf-ruby.git > /dev/null
"$ASDF" plugin add golang https://github.com/asdf-community/asdf-golang.git > /dev/null
"$ASDF" plugin add rust https://github.com/asdf-community/asdf-rust.git > /dev/null
"$ASDF" plugin add terraform https://github.com/asdf-community/asdf-hashicorp.git > /dev/null
"$ASDF" plugin update --all > /dev/null
fi
##### shell #####
if [[ "$OSTYPE" == "darwin"* && "$SHELL" != "$(brew --prefix)/bin/bash" && -x "$(brew --prefix)/bin/bash" ]]; then
echo "changing default shell to $(brew --prefix)/bin/bash"
if ! grep -q "$(brew --prefix)/bin/bash" /etc/shells; then
echo "$(brew --prefix)/bin/bash" | sudo tee -a /etc/shells
fi
sudo chsh -s "$(brew --prefix)/bin/bash" "$USER"
fi
##### automations #####
if [[ "$OSTYPE" == "darwin"* ]]; then
AUTOMATIONS_ROOT="$DEST_HOME/$AUTOMATIONS_ROOT_DIR"
if [ ! -e "$AUTOMATIONS_ROOT" ]; then
if command -v git > /dev/null; then
git clone "$AUTOMATIONS_REPO" "$AUTOMATIONS_ROOT"
git -C "$AUTOMATIONS_ROOT" remote set-url --push origin "$AUTOMATIONS_REPO_SSH"
else
echo "automations installation was skipped (git is not installed)." 1>&2
fi
fi
if [ -e "$AUTOMATIONS_ROOT" ]; then
git -C "$AUTOMATIONS_ROOT" pull > /dev/null && "$AUTOMATIONS_ROOT/install"
fi
fi
##### Mac GUI app #####
if [[ "$OSTYPE" == "darwin"* ]]; then
function restart_mac_app () {
APP_NAME="$1"
[ -e "/Applications/$APP_NAME.app" ] && ( osascript -e "quit app \"${APP_NAME}\""; sleep 0.1; open -a "$APP_NAME" )
}
# Clipy
defaults write com.clipy-app.Clipy loginItem -int 1 # この設定を付与した後にClipyを一度も起動しないと、おそらくログイン項目に追加されない
defaults write com.clipy-app.Clipy kCPYPrefMaxHistorySizeKey -int 100
defaults write com.clipy-app.Clipy kCPYPrefNumberOfItemsPlaceInlineKey -int 10
defaults write com.clipy-app.Clipy kCPYPrefNumberOfItemsPlaceInsideFolderKey -int 20
defaults write com.clipy-app.Clipy kCPYPrefMaxMenuItemTitleLengthKey -int 70
defaults write com.clipy-app.Clipy kCPYPrefShowStatusItemKey -int 0
defaults write com.clipy-app.Clipy kCPYBetaDeleteHistory -int 1
defaults read com.clipy-app.Clipy kCPYBetaDeleteHistoryModifier > /dev/null 2>&1 && defaults delete com.clipy-app.Clipy kCPYBetaDeleteHistoryModifier
defaults write com.clipy-app.Clipy kCPYBetaPastePlainText -int 1
defaults write com.clipy-app.Clipy kCPYBetaPastePlainTextModifier -int 2
defaults write com.clipy-app.Clipy kCPYCollectCrashReport -int 0
defaults write com.clipy-app.Clipy kCPYBetaObserveScreenshot -int 1
defaults write com.clipy-app.Clipy kCPYPrefStoreTypesKey "<dict><key>Filenames</key><true/><key>PDF</key><true/><key>RTF</key><true/><key>RTFD</key><true/><key>String</key><true/><key>TIFF</key><true/><key>URL</key><true/></dict>"
defaults write com.clipy-app.Clipy kCPYHotKeyMainKeyCombo "<data>YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGjCwwVVSRudWxs1A0ODxAREhMUViRjbGFzc1ltb2RpZmllcnNXa2V5Q29kZV8QEGRvdWJsZWRNb2RpZmllcnOAAhEDABAfCNIWFxgZWiRjbGFzc25hbWVYJGNsYXNzZXNfEA9NYWduZXQuS2V5Q29tYm+iGhtfEA9NYWduZXQuS2V5Q29tYm9YTlNPYmplY3QIERokKTI3SUxRU1ddZm13f5KUl5man6qzxcjaAAAAAAAAAQEAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAOM=</data>" # Command + Shift + O
defaults write com.clipy-app.Clipy kCPYHotKeySnippetKeyCombo "<data>YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGjCwwVVSRudWxs1A0ODxAREhMUViRjbGFzc1ltb2RpZmllcnNXa2V5Q29kZV8QEGRvdWJsZWRNb2RpZmllcnOAAhELABAfCNIWFxgZWiRjbGFzc25hbWVYJGNsYXNzZXNfEA9NYWduZXQuS2V5Q29tYm+iGhtfEA9NYWduZXQuS2V5Q29tYm9YTlNPYmplY3QIERokKTI3SUxRU1ddZm13f5KUl5man6qzxcjaAAAAAAAAAQEAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAOM=</data>" # Command + Shift + Option + O
defaults read com.clipy-app.Clipy kCPYHotKeyHistoryKeyCombo > /dev/null 2>&1 && defaults delete com.clipy-app.Clipy kCPYHotKeyHistoryKeyCombo
defaults read com.clipy-app.Clipy kCPYClearHistoryKeyCombo > /dev/null 2>&1 && defaults delete com.clipy-app.Clipy kCPYClearHistoryKeyCombo
restart_mac_app Clipy
# Magnet
defaults write com.crowdcafe.windowmagnet expandWindowWestComboKey "<dict><key>keyCode</key><integer>123</integer><key>modifierFlags</key><integer>1572864</integer></dict>"
defaults write com.crowdcafe.windowmagnet expandWindowEastComboKey "<dict><key>keyCode</key><integer>124</integer><key>modifierFlags</key><integer>1572864</integer></dict>"
defaults write com.crowdcafe.windowmagnet maximizeWindowComboKey "<dict><key>keyCode</key><integer>126</integer><key>modifierFlags</key><integer>1572864</integer></dict>"
defaults write com.crowdcafe.windowmagnet launchAtLogin -bool false
defaults write com.crowdcafe.windowmagnet lastRatedVersion -string "99.99.99"
defaults write com.crowdcafe.windowmagnet "NSStatusItem Visible Item-0" -int 0 # 公式な設定はないが強制的に非表示
# restart_mac_app Magnet
# Divvy
defaults write com.mizage.direct.Divvy defaultColumnCount -int 10
defaults write com.mizage.direct.Divvy defaultRowCount -int 10
defaults write com.mizage.direct.Divvy lastColumnCount -int 10
defaults write com.mizage.direct.Divvy lastRowCount -int 10
defaults write com.mizage.direct.Divvy defaultScreenMarginBottom -int 0
defaults write com.mizage.direct.Divvy defaultScreenMarginLeft -int 1 # ステージマネージャー用のスペース
defaults write com.mizage.direct.Divvy defaultScreenMarginRight -int 46 # サイドバー用のスペース
defaults write com.mizage.direct.Divvy defaultScreenMarginTop -int 0
defaults write com.mizage.direct.Divvy enableAcceleration -int 1
defaults write com.mizage.direct.Divvy enableMargins -int 1
defaults write com.mizage.direct.Divvy shortcuts "<data>YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGpCwwUKywzPD1GVSRudWxs0g0ODxNaTlMub2JqZWN0c1YkY2xhc3OjEBESgAKABYAHgAjdFRYXGBkOGhscHR4fICEiIyQlJiIlISgpIypYc2l6ZVJvd3NfEA9zZWxlY3Rpb25FbmRSb3dfEBFzZWxlY3Rpb25TdGFydFJvd1pzdWJkaXZpZGVkVmdsb2JhbF8QEnNlbGVjdGlvbkVuZENvbHVtbldlbmFibGVkW3NpemVDb2x1bW5zV25hbWVLZXlca2V5Q29tYm9Db2RlXxAUc2VsZWN0aW9uU3RhcnRDb2x1bW5da2V5Q29tYm9GbGFncxAKEAkQAAgJgAQJgAMQfhIAmAAAUNItLi8wWiRjbGFzc25hbWVYJGNsYXNzZXNYU2hvcnRjdXSiMTJYU2hvcnRjdXRYTlNPYmplY3TdFRYXGBkOGhscHR4fICEiIyQlJjclITk6IzsICYAEEAQJgAYQexIAmAAAUN0VFhcYGQ4aGxwdHh8gISIjJCUmIiUhOUNERQgJgAQJgAYQfBAFEgCYAADSLS5HSF5OU011dGFibGVBcnJheaNHSUpXTlNBcnJheVhOU09iamVjdAAIABEAGgAkACkAMgA3AEkATABRAFMAXQBjAGgAcwB6AH4AgACCAIQAhgChAKoAvADQANsA4gD3AP8BCwETASABNwFFAUcBSQFLAUwBTQFPAVABUgFUAVkBWgFfAWoBcwF8AX8BiAGRAawBrQGuAbABsgGzAbUBtwG8Ab0B2AHZAdoB3AHdAd8B4QHjAegB7QH8AgACCAAAAAAAAAIBAAAAAAAAAEsAAAAAAAAAAAAAAAAAAAIR</data>"
defaults write com.mizage.direct.Divvy "NSStatusItem Visible Item-0" -int 0 # 公式な設定はないが強制的に非表示
# restart_mac_app Divvy
# Battery Monitor
defaults write com.rockysandstudio.Battery-Diag "Welcome Arrow Shown" -int 1
defaults write com.rockysandstudio.Battery-Diag "Low Battery Notification Percent" -string "0.198473622311828"
defaults write com.rockysandstudio.Battery-Diag JSDefaults -dict-add RatedBundleVersion 99
defaults write com.rockysandstudio.Battery-Diag JSDefaults -dict-add RatingLastLaunchBundleVersion 99
defaults write com.rockysandstudio.Battery-Diag JSDefaults -dict-add NewsletterLastLaunchBundleVersion 99
defaults write com.rockysandstudio.Battery-Diag "NSStatusItem Visible Item-0" -int 0 # 公式な設定はないが強制的に非表示
restart_mac_app "Battery Monitor"
# MonitorControl
defaults write me.guillaumeb.MonitorControl menuIcon -int 2 # always hide
defaults write me.guillaumeb.MonitorControl keyboardVolume -int 3 # disable
defaults write me.guillaumeb.MonitorControl "forceSw(DELLS2721QS426841366@2)" -int 1
restart_mac_app "MonitorControl"
# SoundSource
defaults write com.rogueamoeba.soundsource keyboardVolume -int 1
restart_mac_app SoundSource
fi