-
Notifications
You must be signed in to change notification settings - Fork 8
/
mac
271 lines (219 loc) · 7.7 KB
/
mac
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
#!/usr/bin/env bash
# Ask for the administrator password upfront
sudo -v
# Welcome to the laptop script! Be prepared to turn your laptop (or
# desktop, no haters here) into an awesome development machine.
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
if [[ ! -d "$HOME/.bin/" ]]; then
mkdir "$HOME/.bin"
fi
fancy_echo() {
printf "\n%b\n" "$1"
}
less_fancy_echo() {
printf "%b\n" "$1"
}
function pause(){
read -p "$*"
}
DULL=0
BRIGHT=1
FG_RED=31
FG_GREEN=32
FG_YELLOW=33
FG_WHITE=37
BG_NULL=00
##
# ANSI Escape Commands
##
ESC="\033"
RESET="$ESC[${DULL};${FG_WHITE};${BG_NULL}m"
GREEN="$ESC[${DULL};${FG_GREEN}m"
YELLOW="$ESC[${DULL};${FG_YELLOW}m"
BRIGHT_RED="$ESC[${BRIGHT};${FG_RED}m"
fancy_echo "Initialize SSH ..."
if [ ! -d ~/.ssh/ ]; then
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
fi
start_if_needed() {
local grep_name="[${1:0:1}]${1:1}"
if [[ -z $(ps aux | grep -e "${grep_name}") ]]; then
if [ -e ~/Applications/$1.app ]; then
open ~/Applications/$1.app
else
if [ -e /Applications/$1.app ]; then
open /Applications/$1.app
fi
fi
fi
true
}
fancy_echo "Setting OSX settings ..."
# Disable press-and-hold for keys in favour of key repeat.
defaults write -g ApplePressAndHoldEnabled -bool false
# Set a really fast key repeat.
defaults write NSGlobalDomain KeyRepeat -int 1
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Finder: show hidden files by default
defaults write com.apple.finder AppleShowAllFiles -bool true
# Finder: show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Finder: show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# Finder: show path bar
defaults write com.apple.finder ShowPathbar -bool true
# Finder: allow text selection in Quick Look
defaults write com.apple.finder QLEnableTextSelection -bool true
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Show the ~/Library folder.
chflags nohidden ~/Library
less_fancy_echo "Restarting affected apps, some of these changes require a logout/restart ..."
for app in "cfprefsd" "Finder" "SystemUIServer"; do
killall "${app}" > /dev/null 2>&1
done
fancy_echo "Installing XCode ..."
if [ ! $(xcode-select -p)='/Library/Developer/CommandLineTools' ]; then
less_fancy_echo "${BRIGHT_RED}You must manually install Xcode${RESET}"
less_fancy_echo 'try these commands'
less_fancy_echo '$ sudo xcodebuild -license'
less_fancy_echo '$ xcode-select --install'
less_fancy_echo ''
pause 'Press [Enter] key after Xcode has been installed'
else
less_fancy_echo '... skipping, looks like XCode is installed'
fi
newly_installed_homebrew=0
if ! which brew &>/dev/null; then
fancy_echo "Installing Homebrew ..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
newly_installed_homebrew=1
else
fancy_echo "Homebrew already installed. Skipping ..."
fi
fancy_echo "Updating Homebrew formulas ..."
brew update
brew bundle --file=- <<EOF
tap "thoughtbot/formulae"
tap "homebrew/services"
tap "homebrew/cask-fonts"
brew "git"
brew "the_silver_searcher"
brew "ripgrep"
brew "vim"
brew "ctags"
brew "tmux"
brew "reattach-to-user-namespace"
brew "bash-completion"
brew "nginx"
brew "wget"
brew "chruby"
brew "ruby-install"
brew "rcm"
brew "yarn"
brew "golang"
cask "alfred"
cask "textmate"
cask "iterm2"
cask "font-source-code-pro"
EOF
git_clone() {
if [ ! -d $2 ]; then
git clone $1 $2
else
less_fancy_echo "... skip cloning $1, already cloned"
fi
true
}
start_if_needed iTerm
fancy_echo "Downloading Solarized ..."
if [ ! -d ~/Applications/solarized ]; then
wget https://ethanschoonover.com/solarized/files/solarized.zip
unzip -q solarized.zip
rm solarized.zip
mv solarized ~/Applications/
fi
fancy_echo "Installing Solarized Dark Theme for Terminal ..."
if [ -s ~/Library/Preferences/com.apple.Terminal.plist ]; then
if grep -q 'Solarized Dark' ~/Library/Preferences/com.apple.Terminal.plist; then
echo "... skipping theme install, already installed"
else
open ~/Applications/solarized/osx-terminal.app-colors-solarized/Solarized\ Dark\ ansi.terminal
sleep 1
defaults write com.apple.terminal "Default Window Settings" -string "Solarized Dark ansi"
defaults write com.apple.terminal "Startup Window Settings" -string "Solarized Dark ansi"
fi
else
echo "... skipping theme install, Terminal not installed"
fi
fancy_echo "Installing Solarized Dark Theme for iTerm ..."
if [ -s ~/Library/Preferences/com.googlecode.iterm2.plist ]; then
if grep -q 'Solarized Dark' ~/Library/Preferences/com.googlecode.iterm2.plist; then
echo "... skipping theme install, already installed"
else
open ~/Applications/solarized/iterm2-colors-solarized/Solarized\ Dark.itermcolors
fi
else
echo "... skipping theme install, iTerm 2 not installed"
fi
fancy_echo "Installing chruby ..."
source $(brew --prefix chruby)/share/chruby/chruby.sh
source $(brew --prefix chruby)/share/chruby/auto.sh
find_latest_ruby() {
chruby | tr -d '* ' | grep -x "ruby-.*" | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | head -1
}
fancy_echo "Install and use latest ruby ..."
ruby-install --latest --no-reinstall ruby
latest_ruby_version=$(find_latest_ruby)
chruby ${latest_ruby_version}
echo ${latest_ruby_version} > ~/.ruby-version
fancy_echo "Updating to latest Rubygems version ..."
gem update --system
fancy_echo "Installing Bundler to install project-specific Ruby gems ..."
gem install bundler --no-document --pre
fancy_echo "Configuring Bundler for faster, parallel gem installation ..."
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
fancy_echo "Creating workspace ..."
mkdir -p ~/workspace
fancy_echo "Cloning Dotfiles ..."
git_clone https://github.com/attack/dotfiles.git ~/workspace/dotfiles
git_clone https://github.com/attack/vim-bootstrap.git ~/workspace/vim-bootstrap
fancy_echo "Symlinking Dotfiles ..."
rcup -v -d ~/workspace/dotfiles -x README.md -x Brewfile -x install -x LICENSE -x tags
rcup -v -d ~/workspace/vim-bootstrap -x README.md -x Brewfile -x install -x LICENSE -x tags
fancy_echo "Installing your shared additions from ~/.laptop.shared ..."
if [[ -f ~/.laptop.shared ]]; then
source ~/.laptop.shared
fi
fancy_echo "Installing your personal additions from ~/.laptop.local ..."
if [[ -f ~/.laptop.local ]]; then
source ~/.laptop.local
fi
if [ $newly_installed_homebrew -eq 1 ]; then
fancy_echo "Updating shell config for Homebrew ..."
if [[ -f ~/.zprofile ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
fi
if [[ -f ~/.bash_profile ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
fi
fi
fancy_echo "Cleaning up Brew ..."
brew cleanup
less_fancy_echo ""
less_fancy_echo " ${GREEN}******************"
less_fancy_echo " TODO (manual)"
less_fancy_echo " ******************${RESET}"
less_fancy_echo ""
less_fancy_echo " ${YELLOW}**** USING SYSTEM PREFERENCES${RESET}"
less_fancy_echo " - allow apps downloaded from Anywhere (see Security & Privacy > General)"
less_fancy_echo " - map caps lock to ctrl (see Keyboard > Keyboard > Modifier Keys)"
less_fancy_echo ""
less_fancy_echo " ${YELLOW}**** USING SPECIFIC APPS${RESET}"
less_fancy_echo " - use solarized for Terminal. Theme was installed, just make it default"
less_fancy_echo " - use solarized for iTerm2. Theme was installed, just apply it"
less_fancy_echo ""