Skip to content

Instantly share code, notes, and snippets.

@domtra
Last active May 12, 2021 12:54
Show Gist options
  • Save domtra/bd3f50c3dcfebae9c46e3c618997f145 to your computer and use it in GitHub Desktop.
Save domtra/bd3f50c3dcfebae9c46e3c618997f145 to your computer and use it in GitHub Desktop.

Mac Setup

  1. Install xcode command line tools

    xcode-select --install
  2. If you are on a M1 / Apple Silicon chip, install rosetta2

    /usr/sbin/softwareupdate --install-rosetta --agree-to-license
  3. Install homebrew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    At the end of the installation, there will be a command like eval "$(/opt/homebrew/bin/brew shellenv)". Until we are done with the setup, you might have to run this command in every new terminal that you open, before you run a brew command.

  4. Install zsh, so you get the latest version, not the one that comes with macOS

    brew install zsh
  5. Change default shell

    • System Preferences -> Users & Groups
    • Unlock edit mode
    • Right click on your user -> Advanced Options
    • Set Login shell to /opt/homebrew/bin/zsh or /usr/local/bin/zsh, depending on the output of brew --prefix in your terminal
  6. Open a new terminal. If you get a message about Z shell config, hit q to quit the menu.

  7. Add custom homebrew repositories

    brew tap homebrew/bundle
    brew tap homebrew/cask
    brew tap homebrew/cask-fonts
    brew tap homebrew/cask-versions
    brew tap homebrew/core
    brew tap homebrew/services
    brew tap mas-cli/tap
  8. Add additional core / linux packages to get the latest version instead of the ones bundled with macOS and to get more linux like functionality.

    brew install pkg-config bash coreutils findutils grep rsync git gnu-sed vim wget pwgen zsh mas
  9. Install casks, macOS gui applications.

    brew install --cask 1password adium firefox google-chrome google-chrome-canary google-drive-file-stream grandperspective iterm2 kaleidoscope sequel-pro slack spectacle teamviewer visual-studio-code yemuzip
  10. Install zplug

    curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
  11. Edit the file ~/.zshrc to be

    eval $(/opt/homebrew/bin/brew shellenv)
    source ~/.zplug/init.zsh
    
    zplug 'zplug/zplug', hook-build:'zplug --self-manage'
    
    zplug "modules/history", from:prezto
    zplug "zsh-users/zsh-autosuggestions", defer:3
    zplug "zsh-users/zsh-completions"
    zplug "zsh-users/zsh-syntax-highlighting", defer:1
    zplug "zsh-users/zsh-history-substring-search", defer:2
    
    zplug "modules/osx", from:prezto
    zplug "plugins/git",   from:oh-my-zsh
    
    zplug mafredri/zsh-async, from:github
    zplug sindresorhus/pure, use:pure.zsh, from:github, as:theme
    
    # Install plugins if there are plugins that have not been installed
    if ! zplug check --verbose; then
        printf "Install? [y/N]: "
        if read -q; then
            echo; zplug install
        fi
    fi
    
    run () {
        if [ -f "./run" ]; then
            ./run "$@"
        fi
    }
    
    bindkey '^[[A' history-substring-search-up
    bindkey '^[[B' history-substring-search-down
    
    # Prefer US English and use UTF-8.
    export LANG='en_US.UTF-8';
    export LC_ALL='en_US.UTF-8';
    
    export PATH=~/bin:$PATH
    
    unset LSCOLORS
    export CLICOLOR=1
    export CLICOLOR_FORCE=1
    
    zstyle ':completion:*' menu select
    
    # zplug load --verbose
    zplug load

    When you now start a new terminal, you need to confirm the installation of all specified modules with hitting y. Also, run compaudit | xargs chmod g-w to set the right permissions for Z shell's shared folder.

  12. Edit the file ~/.gitconfig to be

    # set your user tokens as environment variables, such as ~/.secrets
    # See the README for examples.
    [color]
    ui = true
    [color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
    [color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red
    new = green
    [alias]
    # add
    a = add                           # add
    chunkyadd = add --patch           # stage commits chunk by chunk
    
    # via http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
    snapshot = !git stash save "snapshot: $(date)" && git stash apply "stash@{0}"
    snapshots = !git stash list --grep snapshot
    
    #via http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
    recent-branches = !git for-each-ref --count=15 --sort=-committerdate refs/heads/ --format='%(refname:short)'
    
    # branch
    b = branch -v                     # branch (verbose)
    
    # commit
    c = commit -m                     # commit with message
    ca = commit -am                   # commit all with message
    ci = commit                       # commit
    amend = commit --amend            # ammend your last commit
    ammend = commit --amend           # ammend your last commit
    
    # checkout
    co = checkout                     # checkout
    nb = checkout -b                  # create and switch to a new branch (mnemonic: "git new branch branchname...")
    
    # cherry-pick
    cp = cherry-pick -x               # grab a change from a branch
    
    # diff
    d = diff                          # diff unstaged changes
    dc = diff --cached                # diff staged changes
    last = diff HEAD^                 # diff last committed change
    
    # log
    l = log --graph --date=short
    changes = log --pretty=format:\"%h %cr %cn %Cgreen%s%Creset\" --name-status
    short = log --pretty=format:\"%h %cr %cn %Cgreen%s%Creset\"
    simple = log --pretty=format:\" * %s\"
    shortnocolor = log --pretty=format:\"%h %cr %cn %s\"
    
    # pull
    pl = pull                         # pull
    
    # push
    ps = push                         # push
    
    # rebase
    rc = rebase --continue            # continue rebase
    rs = rebase --skip                # skip rebase
    
    # remote
    r = remote -v                     # show remotes (verbose)
    
    # reset
    unstage = reset HEAD              # remove files from index (tracking)
    uncommit = reset --soft HEAD^     # go back before last commit, with files in uncommitted state
    filelog = log -u                  # show changes to a file
    mt = mergetool                    # fire up the merge tool
    
    # stash
    ss = stash                        # stash changes
    sl = stash list                   # list stashes
    sa = stash apply                  # apply stash (restore changes)
    sd = stash drop                   # drop stashes (destory changes)
    
    # status
    s = status                        # status
    st = status                       # status
    stat = status                     # status
    
    # tag
    t = tag -n                        # show tags with <n> lines of each tag message
    
    # svn helpers
    svnr = svn rebase
    svnd = svn dcommit
    svnl = svn log --oneline --show-commit
    gi = "!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi"
    ignore = "!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi"
    [format]
    pretty = format:%C(blue)%ad%Creset %C(yellow)%h%C(green)%d%Creset %C(blue)%s %C(magenta) [%an]%Creset
    #[mergetool]
    #  prompt = false
    #[mergetool "mvimdiff"]
    #  cmd="mvim -c 'Gdiff' $MERGED"     # use fugitive.vim for 3-way merge
    #  keepbackup=false
    #[merge]
    #  summary = true
    #  verbosity = 1
    #  tool = mvimdiff
    [apply]
    whitespace = nowarn
    [branch]
    autosetupmerge = true
    [push]
    # 'git push' will push the current branch to its tracking branch
    # the usual default is to push all branches
    default = upstream
    [core]
    autocrlf = false
    editor = vim
    [advice]
    statusHints = false
    [diff]
    # Git diff will use (i)ndex, (w)ork tree, (c)ommit and (o)bject
    # instead of a/b/c/d as prefixes for patches
    mnemonicprefix = true
    algorithm = patience
    tool = Kaleidoscope
    [rerere]
    # Remember my merges
    # http://gitfu.wordpress.com/2008/04/20/git-rerere-rereremember-what-you-did-last-time/
    enabled = true
    [include]
    path = .gitconfig.user
    [difftool "Kaleidoscope"]
    cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
    #[diff]
    #  tool = Kaleidoscope
    [difftool]
    prompt = false
    
    [mergetool "Kaleidoscope"]
    cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
    trustExitCode = true
    [mergetool]
    prompt = false
    [merge]
    tool = Kaleidoscope
    [credential]
    helper = osxkeychain
    [filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true

    Set you GitHub username and email address globally:

    git config --global user.name "Mona Lisa"
    git config --global user.email "email@example.com"
  13. Highly optional: set sensible developer defaults for macOS. Check https://mths.be/macos for instructions.

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