Published on

Mac Toolset

Authors

Similar to my previous toolset pages this page lists the setup I use on new Macs. The Mac setup ended up being a breeze especially with the Homebrew installer script and Homebrew itself streamlining the whole process.

Install Homebrew and OSX Command Line Tools

First I installed Homebrew by simply running the install line from the official site:

# install homebrew
## This also installs the OSX command line tools and git
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This installed the OSX command line tools as well as Git and Homebrew.

Install Everything Else

With Homebrew setup the rest of the install process is trivial. Programs/tools can be manually installed by running brew install thing or brew cask install thing.

But in future I can simply run an export of my setup by running brew bundle dump. Which outputs a BrewFile. This file can then be run on another Mac with Homebrew installed by cding to the folder with this BrewFile and running brew bundle. The BrewFile I like to use is below:

tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/core"
tap "homebrew/services"
brew "fasd"
# very cool tool to look through logs: https://lnav.org/
brew "lnav"
brew "neovim"
brew "redis", restart_service: true
brew "screen"
brew "wget"
brew "yarn"
cask "alfred"
cask "docker"
cask "emacs"
cask "firefox"
cask "ganache"
cask "google-chrome"
cask "hammerspoon"
cask "iterm2"
cask "menumeters"
cask "spectacle"
cask "visual-studio-code"
cask "vlc"
cask "itsycal"

Simple Brew cheatsheet:

CommandExampleDescription
searchbrew cask search redisSearching brew casks and formulae for redis
servicesbrew services list AND brew services redis startList services and start the redis service
doctorbrew doctorDetect and fix broken formulae and casks

.zshrc Modifications

## use the agnoster theme
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

DEFAULT_USER=`whoami`

prompt_context() {
  # Custom (Random emoji)
  emojis=("⚡️" "🔥" "💀" "👑" "😎" "🐸" "🐵" "🦄" "🌈" "🍻" "🚀" "💡" "🎉" "🔑" "🇹🇭" "🚦" "🌙")
  RAND_EMOJI_N=$(( $RANDOM % ${#emojis[@]} + 1))
  prompt_segment black default "${emojis[$RAND_EMOJI_N]} "
}

test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

## Git aliases
alias g='git'
alias gitr='git pull --rebase'
alias gitp='git push'
alias gr='git pull --rebase'
alias gp='git push'
# commit and sign commits
alias gc='git commit -vs'
alias ga='git add .'

## Docker Aliases
# For when you really need to clear up space
alias dockernuke='docker rmi $(docker images -q) || docker volumes prune -f || docker network prune -f || docker system prune -f'
# To stop all containers (sac)
alias dockersac='docker kill $(docker ps -q)'
# To delete stopped containers (dsc)
alias dockerdsc='docker rm $(docker ps -a -q)'
alias dps='docker ps'
alias dpsa='docker ps -a'

## Emacs
# Opens up a terminal version of emacs, if you have the daemon running it'll open much faster
alias ec='emacsclient -nw -c'

## Moving around
# https://brettterpstra.com/2013/02/09/quick-tip-jumping-to-the-finder-location-in-terminal/
# cd to the path of the front Finder window
cdf() {
	target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
	if [ "$target" != "" ]; then
		cd "$target"; pwd
	else
		echo 'No Finder window found' >&2
	fi
}

iTerm2 Cheatsheet

CommandDescription
CMD+Shift+DSplit Horizontally
CMD+DSplit Vertically
CMD+]Move to the right or bottom split
CMD+[Move to the left or top split
CMD+Shift+EnterToggle fulltab for the current split