Skip to content

Instantly share code, notes, and snippets.

@aaronsmulktis
Forked from millermedeiros/osx_setup.md
Last active August 1, 2022 20:00
Show Gist options
  • Save aaronsmulktis/8c804f306a48a0c2fe4b88f0a4ce1af7 to your computer and use it in GitHub Desktop.
Save aaronsmulktis/8c804f306a48a0c2fe4b88f0a4ce1af7 to your computer and use it in GitHub Desktop.
Mac OS X setup

Setup Mac OS X

==============

This note is just for personal reference in case I need to setup a new computer.

Edit: I've done the same process every couple years since 2013 (Mountain Lion, Mavericks and High Sierra).

Consider using Boxen to automate the installation of all necessary and desired softwares and tools.

If no Boxen, proceed... Use With Care

Instructions


1. Software Update

Make sure your Operating System is up to date.

2. Install Xcode and/or "Command Line Tools" (Apple's CLI package)

"Command Line Tools" can be downloaded separate from Xcode at https://developer.apple.com/downloads/ - It is way smaller than installing the whole Xcode but might not work for all cases tho.

Xcode can be found on App Store. (Preferred Method of Installation)

**If Command Line Tools must be reinstalled & downloaded again separately: Here's more info on how to download Command Line Tools inside XCode can be found on StackOverflow

3. Install homebrew and other CLI tools

http://brew.sh/

# install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install git
brew install node
brew install wget
brew install z
brew install ag
brew install ack
brew install ffind
brew install fpp
brew install tmux
brew install watchman

npm install -g ipt
npm install -g http-server
npm install -g esformatter
npm install -g prettier
npm install -g eslint
# yeah, haters gonna hate
npm install -g replace
npm install -g yarn

# TO DO: Add ReactNative, Expo, FFMpeg, SoX, Rust, Python

4. Install softwares

homebrew-cask

Many softwares can be installed through homebrew-cask, which store many additional installation files:

# essential
brew cask install dropbox
brew cask install 1password
brew cask install sensiblesidebuttons

# dev
brew cask install charles
brew cask install imagealpha
brew cask install imageoptim
brew cask install iterm2
brew cask install macvim
brew cask install sequel-pro
brew cask install virtualbox
brew cask install vagrant

# utils
brew cask install divvy
brew cask install istat-menus
brew cask install the-unarchiver
brew cask install vlc

# browsers
brew cask install firefox
brew cask install google-chrome
brew cask install brave-browser

# others
brew cask install limechat
brew cask install skype
brew cask install rightzoom

# quick look plugins (https://github.com/sindresorhus/quick-look-plugins)
brew cask install qlcolorcode qlstephen qlmarkdown quicklook-json qlimagesize webpquicklook suspicious-package quicklookase qlvideo

App Store

  • Gifski (convert video into high-quality Gifs)
  • Amphetamine (prevent mac from sleeping)

Manually

5. Borrow a few OSX settings from mathiasbynens dotfiles

###############################################################################
# General UI/UX                                                               #
###############################################################################

# Disable the sound effects on boot
sudo nvram SystemAudioVolume=" "

# Menu bar: show remaining battery time (on pre-10.8); hide percentage
defaults write com.apple.menuextra.battery ShowPercent -string "NO"
defaults write com.apple.menuextra.battery ShowTime -string "YES"


###############################################################################
# Finder                                                                      #
###############################################################################

# 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: 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

# 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 :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


###############################################################################
# Screen                                                                      #
###############################################################################

# 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


###############################################################################
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility                   #
###############################################################################

# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
# Open and save files as UTF-8 in TextEdit
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4


###############################################################################
# Time Machine                                                                #
###############################################################################

# Prevent Time Machine from prompting to use new hard drives as backup volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true


###############################################################################
# Spotlight                                                                   #
###############################################################################

# Hide Spotlight tray-icon (and subsequent helper)
#sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
# Disable Spotlight indexing for any volume that gets mounted and has not yet
# been indexed before.
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"
# Change indexing order and disable some file types
defaults write com.apple.spotlight orderedItems -array \
  '{"enabled" = 1;"name" = "APPLICATIONS";}' \
  '{"enabled" = 1;"name" = "SYSTEM_PREFS";}' \
  '{"enabled" = 1;"name" = "DIRECTORIES";}' \
  '{"enabled" = 0;"name" = "PDF";}' \
  '{"enabled" = 0;"name" = "FONTS";}' \
  '{"enabled" = 0;"name" = "DOCUMENTS";}' \
  '{"enabled" = 0;"name" = "MESSAGES";}' \
  '{"enabled" = 0;"name" = "CONTACT";}' \
  '{"enabled" = 0;"name" = "EVENT_TODO";}' \
  '{"enabled" = 0;"name" = "IMAGES";}' \
  '{"enabled" = 0;"name" = "BOOKMARKS";}' \
  '{"enabled" = 0;"name" = "MUSIC";}' \
  '{"enabled" = 0;"name" = "MOVIES";}' \
  '{"enabled" = 0;"name" = "PRESENTATIONS";}' \
  '{"enabled" = 0;"name" = "SPREADSHEETS";}' \
  '{"enabled" = 0;"name" = "SOURCE";}'
# Load new settings before rebuilding the index
killall mds
# Make sure indexing is enabled for the main volume
sudo mdutil -i on /
# Rebuild the index from scratch
sudo mdutil -E /

source: https://github.com/mathiasbynens/dotfiles/blob/master/.macos

6. Create/Update ~/.bash_profile

export PS1='\w \$ '

set -o vi

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export NODE_PATH="/usr/local/lib/node_modules:$NODE_PATH"

alias gvim="/Applications/MacVim.app/Contents/MacOS/Vim -g"
alias g="gvim --remote-silent"
alias cask="brew cask"

alias ipt-lg="git log --pretty=format:'%h | %<(80)%s | %<(12)%cr | %<(20)%an | %d' -15 | ipt --size 15 | sed 's#^[^0-9a-z]*\([0-9a-z]*\).*#\1#' | xargs git checkout"
alias ipt-branch="git branch | ipt | xargs git checkout"
alias ipt-vim="ipt -pm | xargs -o vim"
alias ipt-gvim="ipt -pm | xargs -o gvim --remote-silent"

# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
if [ -f ~/.bash/git-completion.sh ]; then
    source ~/.bash/git-completion.sh
fi

# `npm completion > ~/.bash/npm-completion.bash`
if [ -f ~/.bash/npm-completion.sh ]; then
    source ~/.bash/npm-completion.sh
fi

# borrowed from http://petdance.com/2013/04/my-bash-prompt-with-gitsvn-branchstatus-display/
if [ -f ~/.bash/prompt.sh ]; then
    source ~/.bash/prompt.sh
fi

# enable the "z" command
. `brew --prefix`/etc/profile.d/z.sh

7. Create/Update ~/.gitconfig

; I removed the [user] block on purpose so other people don't copy it by mistake
; you will need to set these values
[apply]
    whitespace = fix
[color]
    ui = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan
[merge]
    log = true
[push]
    ; "simple" avoid headaches, specially if you use `--force` w/o specifying branch
    ; see: http://stackoverflow.com/questions/13148066/warning-push-default-is-unset-its-implicit-value-is-changing-in-git-2-0
    default = simple
[url "git://github.com/"]
    insteadOf = "github:"
[url "git@github.com:"]
    insteadOf = "gh:"
    pushInsteadOf = "github:"
    pushInsteadOf = "git://github.com/"
[url "git@github.com:millermedeiros/"]
    insteadOf = "mm:"
[url "git@github.com:mout/"]
    insteadOf = "mout:"
[core]
    excludesfile = ~/.gitignore_global
    ; setting the editor fixes git commit bug http://tooky.co.uk/2010/04/08/there-was-a-problem-with-the-editor-vi-git-on-mac-os-x.html
    editor = /usr/bin/vim
[alias]
    ; show merge tree + commits info
    graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
    lg = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s %Cgreen(%cr)%Creset' --date=relative
    ; basic logging for quick browsing
    ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%cn]" --decorate --numstat
    ; log + file diff
    fl = log -u
    ; find paths that matches the string
    f = "!git ls-files | grep -i"
    ; delete all merged branches
    ; dm = !git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
    ; shortcuts
    cp = cherry-pick
    st = status -s
    cl = clone
    ci = commit
    co = checkout
    br = branch
    dc = diff --cached

You will need to set the user name and email (removed from .gitconfig to avoid errors):

git config --global user.name "Your Name Here"
git config --global user.email youremail@example.com

8. Config vim

my .vimrc is on this gist.

# create symlink to my vimrc file
ln -s ~/Dropbox/dotfiles/vimrc ~/.vimrc
# install Vundle to manage my plugins (https://github.com/VundleVim/Vundle.vim)
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

9. Create/Update ~/.tmux.config

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi C-\ select-pane -l

# refresh 'status-left' and 'status-right' more often
set-option -g status-interval 5

# increase scrollback buffer size
set-option -g history-limit 50000

# address vim mode switching delay (http://superuser.com/a/252717/65504)
set-option -s escape-time 0

# focus events enabled for terminals that support them
set-option -g focus-events on

bind-key C-p previous-window
bind-key C-n next-window

# enable mouse
setw -g mouse on

TODO: borrow tmux settings from @ruyadorno

10a. Re-configure Photos.app to suck less

Great article explaining "the why": https://dev.to/gjbianco/controlling-photoanalysisd-3j2a

# Disable and kill the GUI instance & service for your user!
~$ launchctl disable gui/$UID/com.apple.photoanalysisd && launchctl kill -TERM gui/$UID/com.apple.photoanalysisd
~$ launchctl disable user/$UID/com.apple.photoanalysisd && launchctl kill -TERM user/$UID/com.apple.photoanalysisd

# Disable/enable for entire system!
launchctl disable user/$(id -u)/com.apple.photoanalysisd

#Re-enable:
launchctl enable user/$(id -u)/com.apple.photoanalysisd

# Check disabled status look at the JSON "disabled services" output of:
launchctl print user/$(id -u)

10. Configure npm and generate SSH keys for github

Need to set the npm user:

npm adduser

And also generate SSH keys for github

11. Copy stuff from old HD

# recursively copy files and folders
# beware of rsync `-C, --cvs-exclude` flag since it might exclude files you
# don't want to like *.exe, core, tags...
rsync -av '/Volumes/Macintosh HD/Users/millermedeiros/Projects' ~/tmp_projects
rsync -av '/Volumes/Macintosh HD/Users/millermedeiros/Music/iTunes/iTunes Media' ~/tmp_music

Check if files were copied properly and rename/move. Copying to a temporary folder since rsync might delete files depending on the options and/or merge folders that you do not want to merge.

rsync is great, you should use it when possible.

12. Download IE test VMs for VirtualBox

these take a while to download! so maybe do it on a separate day as a background process...

https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

13. Download a base Ubuntu box for Vagrant

I'm using Vagrant to setup a few VMs locally for development.

The Ubuntu image takes ~2h to download since vagrant server is slow (~50Kb/s), might be faster to download the iso from the Ubuntu site and mount the image by yourself.

# Ubuntu Server 14.04
vagrant box add ubuntu/trusty64

14. Profit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment