Skip to content

Instantly share code, notes, and snippets.

@shcallaway
Last active June 11, 2021 16:19
Show Gist options
  • Select an option

  • Save shcallaway/06d9356076d24ff1d451fb5d8aa55ad6 to your computer and use it in GitHub Desktop.

Select an option

Save shcallaway/06d9356076d24ff1d451fb5d8aa55ad6 to your computer and use it in GitHub Desktop.
Set up a new MacBook with "curl -L dev.sherwoodcallaway.com | sh"
#!/bin/sh
set -e
# =============================
# ========= Homebrew ==========
# =============================
echo "Running Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Brewfile is a nice way to declaritively install things w/ Homebrew.
# https://github.com/Homebrew/homebrew-bundle
cat > ~/Brewfile << EOF
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
brew "aws-iam-authenticator"
brew "awscli"
brew "bash"
brew "bash-completion@2"
brew "bat"
brew "docker", link: false
brew "fzf"
brew "git"
brew "jq"
brew "kubectx"
brew "kubernetes-helm"
brew "node"
brew "postgresql"
brew "rename"
brew "ripgrep"
brew "ruby"
brew "stern"
brew "terraform"
cask "1password"
cask "alfred"
cask "dash"
cask "docker"
cask "firefox"
cask "iterm2"
cask "little-snitch"
cask "moom"
cask "slack"
cask "spotify"
cask "visual-studio-code"
EOF
brew bundle --file ~/Brewfile
rm ~/Brewfile
# =============================
# =========== Vim =============
# =============================
echo "Configuring Vim..."
# Install vim-plug.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
cat > ~/.vimrc << EOF
syntax on
set smartindent
set tabstop=2 shiftwidth=2 expandtab
set number
" Install vim-plug
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'andreypopp/vim-colors-plain'
call plug#end()
set termguicolors
colorscheme plain
EOF
# =============================
# =========== fzf =============
# =============================
echo "Configuring fzf..."
cat > ~/.fzf.zsh << EOF
# Setup fzf
# ---------
if [[ ! "$PATH" == */usr/local/opt/fzf/bin* ]]; then
export PATH="$PATH:/usr/local/opt/fzf/bin"
fi
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/usr/local/opt/fzf/shell/completion.zsh" 2> /dev/null
# Key bindings
# ------------
source "/usr/local/opt/fzf/shell/key-bindings.zsh"
# Preferences
# -----------
export FZF_DEFAULT_OPTS='--layout=reverse'
export FZF_CTRL_R_OPTS='--height=0'
EOF
# =============================
# =========== Git =============
# =============================
echo "Configuring Git..."
# Create an SSH key for use with GitHub.
# https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agentv
echo "Creating new SSH key..."
read -p "Enter GitHub email address: " EMAIL
ssh-keygen -t rsa -b 4096 -C "$EMAIL"
eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/id_rsa
echo "See docs for adding SSH key to GitHub:"
echo "https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account"
cat > ~/.gitconfig << EOF
[user]
name = Sherwood Callaway
email = shcallaway@gmail.com
[url "git@github.com:"]
insteadOf = https://github.com/
[blame]
coloring = highlightRecent
EOF
# =============================
# =========== ZSH =============
# =============================
echo "Configuring ZSH..."
# Install oh-my-zsh.
git clone --depth=1 --branch master https://github.com/robbyrussell/oh-my-zsh ~/.oh-my-zsh
sudo ./.oh-my-zsh/tools/install.sh
cat > ~/.zshrc << EOF
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/sherwoodcallaway/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="random"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
fzf
)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias k=kubectl
alias g=git
alias d=docker
alias dc=docker-compose
alias cat=bat
alias kctx=kubectx
alias kns=kubens
alias tf=terraform
alias grep=rg
# Source fancy fzf preferences.
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
EOF
# Change default shell to ZSH.
chsh -s /bin/zsh
# =============================
# ========== macOS ============
# =============================
echo "Configuring macOS..."
# Ask for the administrator password upfront.
sudo -v
# More macOS options are available here:
# https://ss64.com/osx/syntax-defaults.html
# https://github.com/mathiasbynens/dotfiles/blob/master/.macos
# Close any open System Preferences panes, to prevent them from overriding settings we’re about to change.
osascript -e 'tell application "System Preferences" to quit'
# launchctl is the CLI for launchd, which is basically systemd for macOS.
# Disable Notification Center and remove the menu bar icon.
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2>/dev/null
# Stop iTunes from responding to the keyboard media keys.
# rcd stands for "remote control daemon".
# http://help.beatunes.com/kb/troubleshooting/macos-how-do-i-stop-itunes-from-reacting-to-media-keys
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2>/dev/null
# Enable 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 :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
# Increase grid spacing for icons on the desktop and in other icon views.
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
# Increase the size of icons on the desktop and in other icon views.
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 80" ~/Library/Preferences/com.apple.finder.plist
# Show the ~/Library folder in Finder.
chflags nohidden ~/Library
# Show the /Volumes folder in Finder.
sudo chflags nohidden /Volumes
# defaults is a CLI for manipulating property list ("plist") files.
# https://en.wikipedia.org/wiki/Defaults_(software)
# Set a blazingly fast keyboard repeat rate.
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 20
# Enable the automatic update check for App Store.
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Download updates from App Store in the background.
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1
# Show all processes in Activity Monitor.
defaults write com.apple.ActivityMonitor ShowCategory -int 0
# Sort Activity Monitor results by CPU usage.
defaults write com.apple.ActivityMonitor SortColumn -string "CPUUsage"
defaults write com.apple.ActivityMonitor SortDirection -int 0
# Wipe all app icons from the Dock.
# This is only really useful when setting up a new Mac, or if you don’t use the Dock to launch apps.
defaults write com.apple.dock persistent-apps -array
# Show only open applications in the Dock.
defaults write com.apple.dock static-only -bool true
# Don’t animate opening applications from the Dock.
defaults write com.apple.dock launchanim -bool false
# Disable Dashboard.
defaults write com.apple.dashboard mcx-disabled -bool true
# Don’t show Dashboard as a Space.
defaults write com.apple.dock dashboard-in-overlay -bool true
# Reduce the animation when hiding/showing the Dock.
defaults write com.apple.dock autohide-time-modifier -float 0.25
# Remove the auto-hiding Dock delay.
defaults write com.apple.dock autohide-delay -float 0
# Automatically hide and show the Dock.
defaults write com.apple.dock autohide -bool true
# Make Dock icons of hidden applications translucent.
defaults write com.apple.dock showhidden -bool true
# Don’t show recent applications in Dock.
defaults write com.apple.dock show-recents -bool false
# Disable the Launchpad gesture (pinch with thumb and three fingers).
defaults write com.apple.dock showLaunchpadGestureEnabled -int 0
# Allow quitting Finder via ⌘ + Q; doing so will also hide desktop icons.
defaults write com.apple.finder QuitMenuItem -bool true
# Set Desktop as the default location for new Finder windows.
defaults write com.apple.finder NewWindowTarget -string "PfLo"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/"
# Show icons for hard drives, servers, and removable media on the desktop.
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
# Show hidden files in Finder by default.
defaults write com.apple.finder AppleShowAllFiles -bool true
# Show all filename extensions in Finder.
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Show status bar in Finder.
defaults write com.apple.finder ShowStatusBar -bool true
# Show path bar in Finder.
defaults write com.apple.finder ShowPathbar -bool true
# Display full POSIX path as Finder window title.
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# In Finder, keep folders on top when sorting by name.
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# In Finder, when performing a search, search the current folder by default.
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable the warning when changing a file extension.
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Avoid creating .DS_Store files on network or USB volumes.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Use list view in all Finder windows by default.
# Four-letter codes for the other view modes: `icnv`, `clmv`, `glyv`
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv"
# Disable the warning before emptying the Trash.
defaults write com.apple.finder WarnOnEmptyTrash -bool false
# Require password immediately after sleep or screen saver begins.
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
# Save screenshots to the desktop.
defaults write com.apple.screencapture location -string "${HOME}/Desktop"
# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF).
defaults write com.apple.screencapture type -string "png"
# Disable shadow in screenshots.
defaults write com.apple.screencapture disable-shadow -bool true
# Increase sound quality for Bluetooth headphones.
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 40
# Disable press-and-hold for keys in favor of key repeat.
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Set a blazingly fast keyboard repeat rate.
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10
# Set language and text formats.
defaults write NSGlobalDomain AppleLanguages -array "en" "nl"
defaults write NSGlobalDomain AppleLocale -string "en_US@currency=USD"
defaults write NSGlobalDomain AppleMeasurementUnits -string "Inches"
defaults write NSGlobalDomain AppleMetricUnits -bool false
# Automatically quit printer app once the print jobs complete.
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# systemsetup is used to configure certain per-machine settings typically configured in the System Preferences application.
# You can find more systemsetup commands by running: sudo systemsetup -printCommands
# Set the timezone. See `sudo systemsetup -listtimezones` for other values.
sudo systemsetup -settimezone "America/Los_Angeles" >/dev/null
# Never go into computer sleep mode.
sudo systemsetup -setcomputersleep Off >/dev/null
# pmset is a CLI for manipulating power management settings on macOS.
# I recommend reading the pmset manpage to learn more about what it can do.
# Disable hibernation mode (speeds up entering sleep mode).
sudo pmset -a hibernatemode 0
# Enable lid wakeup.
sudo pmset -a lidwake 1
# Restart automatically on power loss.
sudo pmset -a autorestart 1
# Restart automatically if the computer freezes.
sudo systemsetup -setrestartfreeze on
# Sleep the display after 15 minutes.
sudo pmset -a displaysleep 15
# Disable machine sleep while charging.
sudo pmset -c sleep 0
# Set machine sleep to 5 minutes on battery.
sudo pmset -b sleep 5
# Set standby delay to 24 hours (default is 1 hour).
sudo pmset -a standbydelay 86400
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment