Skip to content

Instantly share code, notes, and snippets.

@robynlarsen
Forked from martinlaws/setup.sh
Created February 10, 2021 16:45
Show Gist options
  • Save robynlarsen/5cb230eab5784cc776dd4a4862950724 to your computer and use it in GitHub Desktop.
Save robynlarsen/5cb230eab5784cc776dd4a4862950724 to your computer and use it in GitHub Desktop.
New Mac Setup Script
#!/bin/sh
start=`date +%s`
bold=$(tput bold)
normal=$(tput sgr0)
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
fancy_echo() {
echo
echo "${bold}$1${normal}"
}
append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="${2:-0}"
if [ -w "$HOME/.zshrc.local" ]; then
zshrc="$HOME/.zshrc.local"
else
zshrc="$HOME/.zshrc"
fi
if ! grep -Fqs "$text" "$zshrc"; then
if [ "$skip_new_line" -eq 1 ]; then
printf "%s\\n" "$text" >> "$zshrc"
else
printf "\\n%s\\n" "$text" >> "$zshrc"
fi
fi
}
fancy_echo "👋 hey there! Let's get started"
fancy_echo "########## 🧹 QUICK HOUSEKEEPING ##########"
# shellcheck disable=SC2154
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
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
# shellcheck disable=SC2016
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
HOMEBREW_PREFIX="/usr/local"
if [ -d "$HOMEBREW_PREFIX" ]; then
if ! [ -r "$HOMEBREW_PREFIX" ]; then
sudo chown -R "$LOGNAME:admin" /usr/local
fi
else
sudo mkdir "$HOMEBREW_PREFIX"
sudo chflags norestricted "$HOMEBREW_PREFIX"
sudo chown -R "$LOGNAME:admin" "$HOMEBREW_PREFIX"
fi
# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
fancy_echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Update homebrew recipes
fancy_echo "Updating homebrew..."
brew update
fancy_echo "########## 🔑 SSH KEY ##########"
fancy_echo "Do you wish to create an SSH key (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptSSHKey
if [ "$OptSSHKey" != "${OptSSHKey#[Yy]}" ] ;then
fancy_echo "Please enter your email address:"
read GitUserEmail
fancy_echo "Creating an SSH key for you..."
ssh-keygen -t rsa -b 4096 -C $GitUserEmail
fancy_echo "Please add this your public key to Github, it's been copied to your clipboard \n"
fancy_echo "Go to this link: https://github.com/account/ssh \n"
read -p "Press [Enter] key when you're done..."
eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/id_rsa
fancy_echo "✅ SSH'd"
else
fancy_echo 👎
fi
fancy_echo "########## ⓧ XCODE ##########"
fancy_echo "Do you wish to install xcode-select (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptXCodeSelect
if [ "$OptXCodeSelect" != "${OptXCodeSelect#[Yy]}" ] ;then
fancy_echo "Installing xcode-select"
xcode-select --install
fancy_echo '✅ Installed xcode-select'
else
fancy_echo 👎
fi
fancy_echo "########## 🌱 GIT ##########"
fancy_echo "Do you wish to configure git (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptGitConfig
if [ "$OptGitConfig" != "${OptGitConfig#[Yy]}" ] ;then
fancy_echo "Installing Git..."
brew install git
fancy_echo "Please enter your name as you'd like it to appear on Git commits:"
read GitUserName
git config --global user.name $GitUserName
fancy_echo "Please enter your email as you'd like it to appear on Git commits:"
read GitUserEmail
git config --global user.email $GitUserEmail
fancy_echo '✅ All done'
else
fancy_echo 👎
fi
fancy_echo "########## 🚀 STARSHIP PROMPT AND ZSH AWESOMENESS ##########"
fancy_echo "Do you want a sick terminal prompt (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptStarshipPrompt
if [ "$OptStarshipPrompt" != "${OptStarshipPrompt#[Yy]}" ] ;then
fancy_echo "Setting ZSH as shell..."
chsh -s /bin/zsh
fancy_echo "Installing 🚀..."
brew install starship
append_to_zshrc 'eval "$(starship init zsh)"'
fancy_echo '✅ All done'
else
fancy_echo 👎
fi
fancy_echo "########## 🍺 BREW UTILITIES ##########"
fancy_echo "Do you wish to install nodejs, yarn, tree, trash, and hub (strongly recommended) (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptBrewUtilities
if [ "$OptBrewUtilities" != "${OptBrewUtilities#[Yy]}" ] ;then
fancy_echo "Installing homebrew utilities"
brew install nodejs
brew install yarn
brew install tree
brew install trash
brew install hub
fancy_echo '✅ Installed brew utilities'
else
fancy_echo 👎
fi
fancy_echo "########## 🤖 ALL THE APPS ##########"
fancy_echo "Do you wish to install the recommended apps (you can always delete anything you don't use) (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptBrewCasks
if [ "$OptBrewCasks" != "${OptBrewCasks#[Yy]}" ] ;then
fancy_echo "Installing homebrew casks"
# Apps
apps=(
1password
amethyst
battle-net
cheatsheet
discord
figma
google-chrome
hyper
kap
miro-formerly-realtimeboard
slack
spotify
tuple
vanilla
windscribe
)
# Install apps to /Applications
# Default is: /Users/$user/Applications
echo "installing apps with Cask..."
brew cask install --appdir="/Applications" ${apps[@]}
brew cask cleanup
fancy_echo '✅ Installed casks'
else
fancy_echo 👎
fi
echo "Cleaning up brew"
brew cleanup
fancy_echo "########## 💻 MAC SETTINGS ##########"
fancy_echo "Do you want to enable opinionated system settings (check out the source code to see what these do) (${bold}${green}y${reset}/${bold}${red}n${reset})? "
read OptSystemSettings
if [ "$OptSystemSettings" != "${OptSystemSettings#[Yy]}" ] ;then
fancy_echo "Alright cowboy, updating system settings..."
#"Disabling system-wide resume"
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false
#"Disabling automatic termination of inactive apps"
defaults write NSGlobalDomain NSDisableAutomaticTermination -bool true
#"Allow text selection in Quick Look"
defaults write com.apple.finder QLEnableTextSelection -bool true
#"Disabling OS X Gate Keeper"
#"(You'll be able to install any app you want from here on, not just Mac App Store apps)"
sudo spctl --master-disable
sudo defaults write /var/db/SystemPolicy-prefs.plist enabled -string no
defaults write com.apple.LaunchServices LSQuarantine -bool false
#"Expanding the save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
#"Automatically quit printer app once the print jobs complete"
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
#"Saving to disk (not to iCloud) by default"
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
#"Check for software updates daily, not just once per week"
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
#"Disable smart quotes and smart dashes as they are annoying when typing code"
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
#"Enabling full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
#"Disabling press-and-hold for keys in favor of a key repeat"
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
#"Setting trackpad & mouse speed to a reasonable number"
defaults write -g com.apple.trackpad.scaling 5
defaults write -g com.apple.mouse.scaling 5
#"Enabling subpixel font rendering on non-Apple LCDs"
defaults write NSGlobalDomain AppleFontSmoothing -int 2
#"Showing icons for hard drives, servers, and removable media on the desktop"
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
#"Showing all filename extensions in Finder by default"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
#"Disabling the warning when changing a file extension"
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
#"Use column view in all Finder windows by default"
defaults write com.apple.finder FXPreferredViewStyle Clmv
#"Avoiding the creation of .DS_Store files on network volumes"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
#"Enabling snap-to-grid for icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
#"Setting the icon size of Dock items to 36 pixels for optimal size/screen-realestate"
defaults write com.apple.dock tilesize -int 36
#"Speeding up Mission Control animations and grouping windows by application"
defaults write com.apple.dock expose-animation-duration -float 0.1
defaults write com.apple.dock "expose-group-by-app" -bool true
#"Setting Dock to auto-hide and removing the auto-hiding delay"
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock autohide-delay -float 0
defaults write com.apple.dock autohide-time-modifier -float 0
#"Setting email addresses to copy as '[email protected]' instead of 'Foo Bar <[email protected]>' in Mail.app"
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false
#"Enabling UTF-8 ONLY in Terminal.app and setting the Pro theme by default"
defaults write com.apple.terminal StringEncodings -array 4
defaults write com.apple.Terminal "Default Window Settings" -string "Pro"
defaults write com.apple.Terminal "Startup Window Settings" -string "Pro"
#"Preventing Time Machine from prompting to use new hard drives as backup volume"
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
#"Disable the sudden motion sensor as its not useful for SSDs"
sudo pmset -a sms 0
#"Speeding up wake from sleep to 24 hours from an hour"
# http://www.cultofmac.com/221392/quick-hack-speeds-up-retina-macbooks-wake-from-sleep-os-x-tips/
sudo pmset -a standbydelay 86400
#"Disable annoying backswipe in Chrome"
defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false
#"Setting screenshots location to ~/Desktop"
mkdir ~/Desktop/Screenshots
defaults write com.apple.screencapture location -string "$HOME/Desktop/Screenshots"
#"Setting screenshot format to PNG"
defaults write com.apple.screencapture type -string "png"
#"Hiding Safari's bookmarks bar by default"
defaults write com.apple.Safari ShowFavoritesBar -bool false
#"Hiding Safari's sidebar in Top Sites"
defaults write com.apple.Safari ShowSidebarInTopSites -bool false
#"Disabling Safari's thumbnail cache for History and Top Sites"
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2
#"Enabling Safari's debug menu"
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
#"Making Safari's search banners default to Contains instead of Starts With"
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
#"Removing useless icons from Safari's bookmarks bar"
defaults write com.apple.Safari ProxiesInBookmarksBar "()"
#"Enabling the Develop menu and the Web Inspector in Safari"
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" -bool true
#"Adding a context menu item for showing the Web Inspector in web views"
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
#"Use `~/Downloads/Incomplete` to store incomplete downloads"
defaults write org.m0k.transmission UseIncompleteDownloadFolder -bool true
defaults write org.m0k.transmission IncompleteDownloadFolder -string "${HOME}/Downloads/Incomplete"
# Don’t automatically rearrange Spaces based on most recent use
defaults write com.apple.dock mru-spaces -bool false
killall Finder
fancy_echo '✅ Overwrote system settings'
else
fancy_echo 👎
fi
runtime=$((($(date +%s)-$start)/60))
fancy_echo "############# ⏲ Total Setup Time ############# $runtime Minutes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment