Skip to content

Commit 78ce43c

Browse files
committed
Newer version of Mac setup script
1 parent 5e8819c commit 78ce43c

File tree

5 files changed

+367
-190
lines changed

5 files changed

+367
-190
lines changed

.github/workflows/macos.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: MacOS Setup
2+
on: [push]
3+
4+
jobs:
5+
setup:
6+
name: Testing MacOS Setup
7+
runs-on: macos-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Setup MacOS Defaults
14+
run: ./defaults.sh
15+
16+
- name: Setup Apps
17+
run: ./install.sh

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
- Paste the following command on your command line
55

66
```shell
7-
$ curl -sL https://raw.githubusercontent.com/codingnirvana/mac-setup-script/master/setup.sh | bash -s $1 $2
8-
```
9-
10-
- Replace $1 and $2 with the following credentials of your GitHub account
11-
- ```GitHub Username```
12-
- ```GitHub email```
7+
$ curl -sL https://raw.githubusercontent.com/codingnirvana/mac-setup-script/master/defaults.sh
8+
$ curl -O https://raw.githubusercontent.com/codingnirvana/mac-setup-script/master/install.sh
9+
chmod +x install.sh
10+
./install.sh --git-name <User Name> --git-email <Email>
11+
```

defaults.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
# Adapted from https://github.com/mathiasbynens/dotfiles/blob/master/.macos
4+
5+
set -x
6+
7+
if [[ -z "${CI}" ]]; then
8+
sudo -v # Ask for the administrator password upfront
9+
# Keep-alive: update existing `sudo` time stamp until script has finished
10+
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
11+
fi
12+
13+
# Trackpad: enable tap to click for this user and for the login screen
14+
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
15+
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
16+
defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
17+
18+
# Disable the sound effects on boot
19+
sudo nvram SystemAudioVolume=" "
20+
21+
# Close any open System Preferences panes, to prevent them from overriding settings we’re about to change
22+
osascript -e 'tell application "System Preferences" to quit'
23+
24+
# Expand save panel by default
25+
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
26+
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
27+
28+
# Expand print panel by default
29+
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
30+
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
31+
32+
# Save to disk (not to iCloud) by default
33+
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
34+
35+
# Automatically quit printer app once the print jobs complete
36+
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
37+
38+
# Disable the “Are you sure you want to open this application?” dialog
39+
defaults write com.apple.LaunchServices LSQuarantine -bool false
40+
41+
# Reveal IP address, hostname, OS version, etc. when clicking the clock in the login window
42+
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
43+
44+
# Disable auto corrections
45+
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false # Disable automatic capitalization
46+
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false # Disable smart dashes
47+
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false # Disable automatic period substitution
48+
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false # Disable smart quotes
49+
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false # Disable auto-correct
50+
51+
# Enable full keyboard access for all controls e.g. enable Tab in modal dialogs
52+
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
53+
54+
# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons
55+
defaults write com.apple.finder QuitMenuItem -bool true
56+
57+
# Set Desktop as the default location for new Finder windows
58+
defaults write com.apple.finder NewWindowTarget -string "PfDe"
59+
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Desktop/"
60+
61+
defaults write com.apple.finder AppleShowAllFiles -bool true # Finder: Show hidden files by default
62+
defaults write NSGlobalDomain AppleShowAllExtensions -bool true # Finder: Show all filename extensions
63+
defaults write com.apple.finder ShowStatusBar -bool true # Finder: Show status bar
64+
defaults write com.apple.finder ShowPathbar -bool true # Finder: Show path bar
65+
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true # Finder: Display full POSIX path as window title
66+
defaults write com.apple.finder _FXSortFoldersFirst -bool true # Finder: Keep folders on top when sorting by name
67+
chflags nohidden ~/Library # Show the ~/Library folder
68+
sudo chflags nohidden /Volumes # Show the /Volumes folder
69+
70+
# Avoid creating .DS_Store files on network or USB volumes
71+
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
72+
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
73+
74+
# Automatically open a new Finder window when a volume is mounted
75+
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
76+
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
77+
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
78+
79+
# Use list view in all Finder windows by default (codes for the other view modes: `icnv`, `clmv`, `Flwv`)
80+
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
81+
82+
# Expand the following File Info panes:
83+
# “General”, “Open with”, and “Sharing & Permissions”
84+
defaults write com.apple.finder FXInfoPanesExpanded -dict \
85+
General -bool true \
86+
OpenWith -bool true \
87+
Privileges -bool true
88+
89+
# Don’t automatically rearrange Spaces based on most recent use
90+
defaults write com.apple.dock mru-spaces -bool false
91+
92+
# Automatically hide and show the Dock
93+
defaults write com.apple.dock autohide -bool true
94+
95+
# Put the Dock on the left of the screen
96+
defaults write com.apple.dock orientation -string "left"
97+
98+
# Prevent Time Machine from prompting to use new hard drives as backup volume
99+
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
100+
101+
# Show the main window when launching Activity Monitor
102+
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
103+
104+
# Visualize CPU usage in the Activity Monitor Dock icon
105+
defaults write com.apple.ActivityMonitor IconType -int 5
106+
107+
# Show all processes in Activity Monitor
108+
defaults write com.apple.ActivityMonitor ShowCategory -int 0
109+
110+
# Sort Activity Monitor results by CPU usage
111+
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
112+
defaults write com.apple.ActivityMonitor SortDirection -int 0

install.sh

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
#!/bin/bash
2+
3+
# Install some stuff before others!
4+
important_casks=(
5+
dropbox
6+
google-chrome
7+
slack
8+
visual-studio-code
9+
)
10+
11+
brews=(
12+
bash
13+
git
14+
git-extras
15+
htop
16+
httpie
17+
iftop
18+
jq
19+
mtr
20+
node
21+
nmap
22+
python3
23+
ruby
24+
scala
25+
solidity
26+
telnet
27+
tmux
28+
trash
29+
tree
30+
vim --with-override-system-vi
31+
watch
32+
wget --with-iri
33+
zsh
34+
)
35+
36+
casks=(
37+
adobe-acrobat-pro
38+
alfred
39+
discord
40+
docker
41+
firefox
42+
freemind
43+
google-backup-and-sync
44+
intellij-idea-ce
45+
iterm2
46+
kindle
47+
ledger-live
48+
libreoffice
49+
rectangle
50+
roam-research
51+
sublime-text
52+
telegram
53+
the-unarchiver
54+
vlc
55+
vuescan
56+
zoom
57+
)
58+
59+
pips=(
60+
pip
61+
)
62+
63+
64+
gpg_key=''
65+
git_email='[email protected]'
66+
git_configs=(
67+
"branch.autoSetupRebase always"
68+
"color.ui auto"
69+
"core.autocrlf input"
70+
"credential.helper osxkeychain"
71+
"merge.ff false"
72+
"pull.rebase true"
73+
"push.default simple"
74+
"rebase.autostash true"
75+
"rerere.autoUpdate true"
76+
"remote.origin.prune true"
77+
"rerere.enabled true"
78+
"user.name codingnirvana"
79+
"user.email ${git_email}"
80+
"user.signingkey ${gpg_key}"
81+
)
82+
83+
vscode=(
84+
bierner.markdown-preview-github-styles
85+
dbaeumer.vscode-eslint
86+
dbankier.vscode-instant-markdown
87+
golang.go
88+
JuanBlanco.solidity
89+
k--kato.intellij-idea-keybindings
90+
ms-python.python
91+
ms-vscode.cpptools
92+
ms-vsliveshare.vsliveshare
93+
ms-vsliveshare.vsliveshare-audio
94+
ms-vsliveshare.vsliveshare-pack
95+
rebornix.ruby
96+
redhat.java
97+
rust-lang.rust
98+
rust-lang.rust-analyzer
99+
scala-lang.scala
100+
)
101+
102+
103+
104+
######################################## End of app list ########################################
105+
set +e
106+
set -x
107+
108+
109+
function prompt {
110+
if [[ -z "${CI}" ]]; then
111+
read -p "Hit Enter to $1 ..."
112+
fi
113+
}
114+
115+
function install {
116+
cmd=$1
117+
shift
118+
for pkg in "$@";
119+
do
120+
exec="$cmd $pkg"
121+
#prompt "Execute: $exec"
122+
if ${exec} ; then
123+
echo "Installed $pkg"
124+
else
125+
echo "Failed to execute: $exec"
126+
if [[ ! -z "${CI}" ]]; then
127+
exit 1
128+
fi
129+
fi
130+
done
131+
}
132+
133+
function brew_install_or_upgrade {
134+
if brew ls --versions "$1" >/dev/null; then
135+
if (brew outdated | grep "$1" > /dev/null); then
136+
echo "Upgrading already installed package $1 ..."
137+
brew upgrade "$1"
138+
else
139+
echo "Latest $1 is already installed"
140+
fi
141+
else
142+
brew install "$1"
143+
fi
144+
}
145+
146+
if [[ -z "${CI}" ]]; then
147+
sudo -v # Ask for the administrator password upfront
148+
# Keep-alive: update existing `sudo` time stamp until script has finished
149+
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
150+
fi
151+
152+
if test ! "$(command -v brew)"; then
153+
prompt "Install Homebrew"
154+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
155+
else
156+
if [[ -z "${CI}" ]]; then
157+
prompt "Update Homebrew"
158+
brew update
159+
brew upgrade
160+
brew doctor
161+
fi
162+
fi
163+
export HOMEBREW_NO_AUTO_UPDATE=1
164+
165+
echo "Install important software ..."
166+
brew tap homebrew/cask-versions
167+
install 'brew cask install' "${important_casks[@]}"
168+
169+
prompt "Install packages"
170+
install 'brew_install_or_upgrade' "${brews[@]}"
171+
brew link --overwrite ruby
172+
173+
prompt "Install JDK=${JDK_VERSION}"
174+
curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh
175+
jabba install ${JDK_VERSION}
176+
jabba alias default ${JDK_VERSION}
177+
java -version
178+
179+
prompt "Set git defaults"
180+
for config in "${git_configs[@]}"
181+
do
182+
git config --global ${config}
183+
done
184+
185+
# if [[ -z "${CI}" ]]; then
186+
# gpg --keyserver hkp://pgp.mit.edu --recv ${gpg_key}
187+
# prompt "Export key to Github"
188+
# ssh-keygen -t rsa -b 4096 -C ${git_email}
189+
# pbcopy < ~/.ssh/id_rsa.pub
190+
# open https://github.com/settings/ssh/new
191+
# fi
192+
193+
prompt "Upgrade bash"
194+
brew install bash bash-completion2 fzf
195+
sudo bash -c "echo $(brew --prefix)/bin/bash >> /private/etc/shells"
196+
sudo chsh -s "$(brew --prefix)"/bin/bash
197+
# Install https://github.com/twolfson/sexy-bash-prompt
198+
touch ~/.bash_profile # see https://github.com/twolfson/sexy-bash-prompt/issues/51
199+
(cd /tmp && git clone --depth 1 --config core.autocrlf=false https://github.com/twolfson/sexy-bash-prompt && cd sexy-bash-prompt && make install) && source ~/.bashrc
200+
hstr --show-configuration >> ~/.bashrc
201+
202+
echo "
203+
alias del='mv -t ~/.Trash/'
204+
alias ls='exa -l'
205+
alias cat=bat
206+
" >> ~/.bash_profile
207+
208+
echo "Setting up zsh ..."
209+
curl -L http://install.ohmyz.sh | sh
210+
chsh -s $(which zsh)
211+
212+
prompt "Install software"
213+
install 'brew cask install' "${casks[@]}"
214+
215+
prompt "Install secondary packages"
216+
install 'pip3 install --upgrade' "${pips[@]}"
217+
install 'code --install-extension' "${vscode[@]}"
218+
219+
prompt "Update packages"
220+
pip3 install --upgrade pip setuptools wheel
221+
if [[ -z "${CI}" ]]; then
222+
m update install all
223+
fi
224+
225+
if [[ -z "${CI}" ]]; then
226+
prompt "Install software from App Store"
227+
mas list
228+
fi
229+
230+
prompt "Cleanup"
231+
brew cleanup
232+
233+
echo "Done!"

0 commit comments

Comments
 (0)