Setup macOS 2021 For Optimal Command Line Productivity

Setup Modern Command Line Tools

here’s a quick guide for setting up modern command line environments on a fresh macOS Monterey 12+ as of late 2021.

Enjoy.

stop saving screenshots directly to destop

We no longer need to defaults write com.apple.screencapture to stop all screenshots going to ~/Desktop/ by default. Instead, just do a regular CMD+SHIFT+5 then click the lower screen toolbar Options menu, and select a better directory for all future screen captures!

install homebrew:

install modern tools:

configure things good

# install good helpers for things
npm install -g uglify-js 

# install python versions you like to run:
pyenv install 3.10.0
pyenv global 3.10.0

# configure git properly along with good helpers
git config --global user.name "URNAME HERE LOL I DO GIT"
git config --global user.email "buffalo@buffalo.buffalo"

# recent git releases enabled auto-pager for "git branch" which is hella'nnoying
git config --global pager.branch false

# stop git from dropping commit messages because the editor return code isn't stable
git config --global core.editor nvim -f

git config --global alias.llog "log --pretty=fuller"
git config --global alias.logs "log --graph --pretty=format:'%C(magenta)%h%Creset -%C(red)%d%Creset %s %C(dim green)(%cr) %C(cyan)<%an>%Creset' --abbrev-commit"
git config --global alias.rl "reflog --format='%C(auto)%h %<|(20)%gd %C(blue)%cr%C(reset) %gs (%s)'"

git config --global alias.tagdate 'log --date-order --graph --tags --simplify-by-decoration --pretty=format:"%ai %h %d"'
git config --global alias.branchbydate "for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'"
git config --global alias.branchcolor '!for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '"'! a["'$0'"]++'"

# short for "github-add". usage: git gha [github user] [reponame]
git config --global alias.gha '!f() { git remote add $1 https://github.com/$1/$2.git; }; f'

# short for "git pull request". usage: git gpr [github issue-id] [local name]
git config --global alias.gpr '!f() { git fetch origin pull/$1/head:$2; }; f'

git config --global core.pager "diff-so-fancy | bat -p"
git config --global interactive.diffFilter "diff-so-fancy --patch"

# Note: if you don't like the light color shading from these defaults,
#       edit ~/.gitconfig and remove section: [color "diff-highlight"]
diff-so-fancy --set-defaults

setup global python dev/experiment environment

configure optimal DNS performance, in /opt/homebrew/etc/dnsmasq.conf add:

flush all DNS caches:

brew edit dnsmasq and change service launch to (may need to monitor updates and re-change if versions flip underneath you):

start local dns resolver with performance and content fixes

then go to network settings and fix your DNS server to 127.0.0.1


set up neovim for modern editing:

configure neovim with modern plugins

tell neovim to load plugins on startup in ~/.config/nvim/init.vim

run in nvim after the files are in place (may require run/exit/run again):

Install good shell defaults and auto-helper scripts

~/.zshrc updates:

# many themes, but my requirements are:
# prompt must include hostname
# prompt must include full path (not just current directory)
# any metadata like current branches/repos in prompt must not make the prompt line "too long"
# no date/time in prompt
ZSH_THEME="kphoen"
EDITOR=nvim
VISUAL=nvim
PAGER=bat
alias ls="gls --color=auto"
alias moretty="sudo sysctl -w kern.tty.ptmx_max=768"
alias nolo='exiftool -GPSLongitude= -GPSLatitude='
alias po=poetry
alias goodnight='pmset displaysleepnow'
alias pi='echo "scale=60; 4*a(1)" | bc -lq'


# extract frames from a video to individual image files.
# usage: toImgs [movie path] [prefix for output files]
function toImgs() {
    # the "-r 7" says dump 7 images per second of video.
    # You can increase or decrease 'r N' as necessary.
    ffmpeg -i "$1" -r 7 -qscale:v 2 "$2"-%0000d.jpg
}

# add a console "note" command to open a markdown file in the
# current directory named with the current date and any suffix
# provided as arguments to the command.
# usage: note shopping list
function note() {
    note_name=""
    if [[ ! -z "$*" ]]; then
        # Use all arguments as trailing name for note
        # (spaces replaced by dashes)
        note_name="-${*// /-}"
    fi
    nvim $(date "+%Y-%m-%d")$note_name.md
}

# create directory and jump into it with one command
function ccd() {
    mkdir -p "$1"
    cd "$1"
}

# get the binary log of a number
# if you like using 'l' as the default 'ls' shorthand, don't do this i guess.
unalias l
function l()  {
     echo "scale=10; l($1)/l(2)" | bc -lq
}

# do a 2^x
function 2x()  {
    echo "2^$1" | bc -lq                 
}

# do a e^x
function e()  {
    echo "e($1)" | bc -lq                 
}

edit kphoen theme ~/.oh-my-zsh/themes/kphoen.zsh-theme for more compactness:

try to pre-trigger all the macOS directory protection warnings up front

In your home directory, run “find .” or “fd” and accept all OS warnings about allowing Terminal to access your directories so future usage doesn’t unexpectedely encounter errors. You’ll also get an OS warning if you access any remote disks and also local disks in /Volumes/ from a terminal session too.

Install better terminal fonts:

Other recent setup problems:

many python packages still don’t have arm64/M1 binaries yet, so pip/poetry will try to build from source and we need extra arguments for the bulids to find our homebrew locations:

compiling some python packages (scipy specifically) requires:

You can also currently install a scipy 1.8.0 prerelease arm binary package, but arm binary packages don’t exist for current fully released versions (but manually installing custom binaries from other sources breaks poetry deps in a dozen different ways too; best to wait for a new official release to get projects working again).

python package numba is limited to llvm10 which homebrew won’t provide for us, so we need to build it manually: download llvm10, build, then provide extra build environment options where needed:

oh, and of course there’s also a bug with LLVM 10 they never fixed where it uses a bad libxml2 link, so you need to make sure you have libxml2 installed from brew then:

Now you have llvm-config at ~/build/llvm-10.0.1.src/bin/llvm-config and you can re-try your failed numba dependency building/installing with:

erlang versions