Mac Config

Some developer-oriented things for Mac.

Mac Apps

General Things

Hotkeys

I’m never surprised when someone doesn’t know some hotkeys. Here’s some hotkeys Legend = the command key = the shift key = alt/option ^ - the control key

Screenshots

  • ⌘ + ^ + 4 - Take a screenshot of a selectable section of the screen and save the file on your desktop

    • Add in ⇧ Shift and it is copied to clipboard and not saved to desktop

  • ⌘ + ^ + 3 - Take a screenshot of ALL displays (each monitor saved as a different file)

    • Add in ⇧ Shift and it is copied to clipboard and not saved to desktop

    • ⌘ + ^ + 5 - Advanced screenshotting. Too bulky for my tastes

General

  • ⌘ + , - This goes to app settings in MOST apps

  • ⌘ + ; - A lot of JetBrainz apps use this as well (DataGrip etc)

  • ⌘ + W OR Middle click a tab will close it in most apps (Finder, Chrome, etc)

    • ⌘ + W will close the current window if there are not multiple tabs

  • ⌘ + ⇧ + ] OR ⌘ + ⌥ + Right - cycle to the next tab

  • ⌘ + ⇧ + [ OR ⌘ + ⌥ + Left- cycle to the previous tab\

  • ⌘ + ⇧ + . - show/hide hidden files in finder

  • ⌘ + Up - go “up” a directory in finder

Chrome (and most other browsers?)

  • ⌘ + ⌥ + I - open the developer tools

  • ⌘ + T - new tab

  • ⌘ + ⇧ + T - reopen closed tab (repeatable)

  • ⌘ + W - new window

  • ⌘ + ⇧ + W - reopen closed window (repeatable)

  • ⌘ + L - highlight the URL bar

  • ⌘ + Up - top of page

  • ⌘ + Down - bottom of page

  • ⌘ + Back - go back a page

  • ⌘ + Forward - go forward a page

  • ⌘ + ⇧ + ] - cycle to the next tab

  • ⌘ + ⇧ + [ - cycle to the previous tab

Sublime, VSC, most IDEs

This is all a lie. I've moved to neovim via alacritty. I use VSC when a formatter isn't behaving occasionally, and Sublime in the way listed below because it's handy.

nvim config ~/.config/nvim/init.vim

let g:ale_disable_lsp = 1

call plug#begin("~/.vim/plugged")

" Plugin Section
Plug 'lifepillar/vim-gruvbox8'
Plug 'mcchrish/nnn.vim'
Plug 'preservim/nerdtree'
Plug 'dense-analysis/ale'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'jiangmiao/auto-pairs'
Plug 'alvan/vim-closetag'
Plug 'itchyny/lightline.vim'
Plug 'itchyny/vim-gitbranch'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-commentary'
Plug 'APZelos/blamer.nvim'
Plug 'othree/xml.vim'
Plug 'wakatime/vim-wakatime'
Plug 'hashivim/vim-terraform'
Plug 'jvirtanen/vim-hcl'

call plug#end()

" Config Section
if (has("termguicolors"))
	set termguicolors
endif
syntax enable
colorscheme gruvbox8

" Don't put a newline at end of file!
set nofixendofline
" Show absolute line number of current line, relative line number of those
" above/below
set relativenumber number
" Use sysem clipboard
set clipboard=unnamed
let mapleader=" "
" Fix up linebreaks
" First we indent the broken lines properly
set breakindent
" Then we give an indication it's a broken line
set showbreak=----->
"" Show `▸▸` for tabs: 	, `·` for tailing whitespace: 
set list listchars=tab:▸▸,trail:·
" Enable mouse mode - NOTE: do you even like this?
set mouse=a

" nnn
nnoremap <silent> <leader>l :NnnPicker<CR>
let g:nnn#layout = { 'window': { 'width': 0.9, 'height': 0.6, 'highlight': 'Debug' } }

" chadtree
nnoremap <leader>k <cmd>NERDTreeToggle<cr>

" ale
let g:ale_linters = { 'javascript': ['eslint'] }
let g:ale_fixers = { 'javascript': ['eslint'] }
let g:ale_fix_on_save = 1

" Vim Closetag
let g:closetag_filenames = '*.html,*.xhtml,*.xml,*.js'
" let g:closetag_filetypes = 'html,xhtml,jsx,javascript,javascript.jsx'
" let g:closetag_xhtml_filetypes = 'xhtml,javascript.jsx'
" autocmd BufNewFile,BufRead *.js set filetype=javascript.jsx
" autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx

" Lightline status bar
let g:lightline = { 
	\ 'active': {
	\	   'left': [ [ 'mode', 'paste' ],
	\             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
	\ },
	\ 'colorscheme': 'jellybeans',
	\ 'component_function': {
	\ 	'gitbranch': 'gitbranch#name'
	\ }
\ }

" blamer
let g:blamer_enabled = 1
let g:blamer_delay = 600
let g:blamer_show_in_visual_modes = 0
let g:blamer_show_in_insert_modes = 0
let g:blamer_date_format = '%d/%m/%y'

" Set coc node version since we have to downgrade to 9/10 all the time...
let g:coc_node_path = '/usr/local/n/versions/node/14.15.5/bin/node'
" And the whole provider for nvim? See https://neovim.io/doc/user/provider.html
let g:node_host_prog = '/usr/local/n/versions/node/14.15.5/bin/node'
" python
let g:python3_host_prog = '/Users/dslaught/.pyenv/versions/py3nvim/bin/python'

" vim-terraform settings
let g:terraform_align = 1
let g:terraform_fmt_on_save = 1

let NERDTreeShowHidden=1

" Remove the bottom row now that we have lightline
set noshowmode

I personally use the Atom keymap in VSC, so some of these hotkeys might be different from what you use 🤷‍♂️ That said, most IDEs provide a printable cheat sheet, here’s VSC’s: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf

  • ^ + M - jump to matching bracket

  • ⌘ + ⇧ + D - duplicate current line

  • ⌘ + ⇧ + L - place cursor at end of line for every line selected

  • ⌥ + Up/Down OR ⌘ + ^ + Up/Down - move selection up/down (single or multi-line)

  • ⌘ + Shift + F - search across all files in project

  • ^ + Backtick - Open integrated terminal

  • ⌘ + \ - Show/hide side bar (I think this is editor split by default)

Developer

Even if you have a favorite IDE, Sublime is suuuuuuper fast for quick viewing of big JSON files etc. Things you wouldn’t have in a project and want something more than nano or textedit to work with JSON Pretty extension is incredibly handy and very fast

Visual Studio Code

If you don’t use VSC, skip this section.

settings.json

settings.json is incredibly powerful.

A lot of settings can only be set via editing this file. To find it, hit ⌘+⇧ Shift+P to bring up the command palette and type in “settings” and select “Preferences: Open Settings (JSON)” Intellisense works wonders in the settings file, just start typing the name of an extension or whatever and it’ll start listing possible properties. When you select one, it usually automatically shows possible values for that setting.

settings.json supports JS comments // and /* */

Here’s some fun excerpts from my settings.json

    // set a custom title for the VSC window
  "window.title": "${activeEditorShort}${separator}${rootName}${separator}${activeEditorMedium}",
  // multi cursor key is something else by default
    "editor.multiCursorModifier": "ctrlCmd",
  // if you paste in copied code, format it to current editor formatting settings
  // this works with eslint as well
  "editor.formatOnPaste": true,
  // telemetry off, always
  "telemetry.enableCrashReporter": false,
  "telemetry.enableTelemetry": false,
  "gitlens.advanced.telemetry.enabled": false,
  // I've found these optimizations to not be worth the loss of extensions etc
  "editor.largeFileOptimizations": false,
  // if you have enough indentions, this setting keeps things manageable
    "editor.wrappingIndent": "indent",
  // renders some nice unobtrusive lines to show indent level
  "editor.renderIndentGuides": true,
  // Scrollback lines in the built in terminal, absolutely essential
  "terminal.integrated.scrollback": 10000,
  // If you work with someone on Windows or who uses 8 space tabs or something...
  "editor.detectIndentation": false,
  // I personally hate right click pasting in terminals
  "terminal.integrated.rightClickBehavior": "selectWord",
  // Nice little breadcrumbs that are built in
  "breadcrumbs.filePath": "on",
  "breadcrumbs.enabled": true,
  "breadcrumbs.icons": true,

Extensions

I’ve curated a decent array of extensions in a few years of using VSC. Some of these come with VSC by default, but I don’t remember which ones so I’ll point ‘em out anyway.

  • GitLens

    • Just an absolutely amazing all in one Git extension

      • Inline git blame, anyone?

      • All kinds of diffing

      • Seriously it could replace all the other git extensions

  • JSON Tools

    • Minify or prettify JSON. That’s it. That’s all.

  • LintLens

    • Inline and hover info on eslint rules

  • Monokai Pro Themes

    • Best themes I’ve personally found

    • Is a “paid” thing but just has a nag popup on first open of VSC to close

  • npm intellisense

    • Auto-completion of package names etc from npm install’d packages

      • works with require() and import syntax

    • I recommend adding ”npm-intellisense.scanDevDependencies”: true to your settings.json

  • Quokka.js

    • Does some cool things with running JS live as you edit

    • Can be handy while hacking together scripts

    • Free version is somewhat limited, but not enough I’ve even considered paying

  • Rainbow CSV

    • Text in CSVs opened in VSC is color coded by column

  • Select Line Status Bar

    • Shows number of selected lines in status bar

  • TODO Highlight

    • Highlight things like TODO NOTE FIXME etc

    • Can add any arbitrary string to highlight

    • Super customizable

    • Can’t live without

  • Todo Tree

    • Adds a tree view of TODO etc comments

    • As customizable as TODO Highlights

  • Bracket Pair Colorizer

    • Colors brackets different colors to make it easy to identify matching brackets.

    • Has options to show colorized lines indicating scope as well

    • There is a Bracket Pair Colorizer 2 that’s supposed to be faster but I can’t get it to work

    • On large files takes about a second to colorize everything, so some people might not love it

    • Here’s my settings that work quite well for me

      "bracketPairColorizer.forceUniqueOpeningColor": true,
        "bracketPairColorizer.activeScopeCSS": [
            "borderStyle : solid",
            "borderWidth : 1px",
            "borderColor : {color}",
            "opacity : .7"
        ],
      "bracketPairColorizer.consecutivePairColors": [
        "()", "[]", "{}",
        [ "</", ">" ],
        [ "<", "/>" ],
        "<>",
        [
            "Gold",
            "Orchid",
            "LightSkyBlue",
            "Aqua",
            "Coral",
            "Chartreuse",
            "OliveDrab",
            "Orange",
            "White"
        ],
        "Red"
      ],
      "bracketPairColorizer.colorMode": "Consecutive",
      "bracketPairColorizer.highlightActiveScope": true,
      "editor.matchBrackets": "never",
      "bracketPairColorizer.showBracketsInGutter": true,
      "bracketPairColorizer.showVerticalScopeLine": true,
      "bracketPairColorizer.scopeLineCSS": [
        "borderStyle : solid",
        "borderWidth : 1px",
        "borderColor : {color}; opacity: 0.5"
      ],
      "bracketPairColorizer.showHorizontalScopeLine": false,
      "bracketPairColorizer.forceIterationColorCycle": true,

iTerm2 - https://iterm2.com/

We all know this one, but how can we make it better?

!!! I assume you’re using zsh instead of bash. If using bash, there’s probably still ways to do all this stuff, you’ll just have to find them on your own.

Shell

LIES! I've moved to vim. Torture is great.

nano

I use nano over vi because I prefer not to torture myself. If you prefer vi go ahead and skip this section.

First thing to do is update the nano version on your mac

  • Run brew install nano

  • Grab the path brew installed to from the install messages. If you don’t see it, run brew info nano

    • As of right now, this path is /usr/local/Cellar/nano/4.9.3 - newer versions, just change the path

  • add an alias to your bashrc/zshrc alias nano=/usr/local/Cellar/nano/4.9.3/bin/nano

  • Reload your terminal and now you’re using the new nano when you run nano

Syntax highlighting in nano is nice

git

Handy aliases from my ~/.gitconfig - also check out https://github.com/gitalias/gitalias

[alias]
    ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
    rh1 = reset HEAD^ --hard
    ac = !git add . && git commit -am
    undo-commit = reset --soft HEAD~1
    new = checkout -b
    mergetest = "!f(){ git merge --no-commit --no-ff \"$1\"; git merge --abort; echo \"Merge aborted\"; };f "
  • git ls will show a nice compact list view of commits in current repo

  • git rh1 is scary and I never use it, but could be useful to some

  • git ac "commit message" will add all untracked files in current repo and add a commit message

    • you can add additional -m “next line" to add more lines, but they will have an extra linebreak

    • Alternatively, commit messages respect \n for new lines so you can do git ac “Commit title\nfirst additional line\nsecond additional line"

  • git undo-commit is also scary and I never use it, but you might like it

  • git new branch_name creates a new branch with branch_name IE git new feature/PSI-9999

  • git mergetest allows you to dry run a merge attempt to see if there are any conflicts

CLI tools

  • goto - https://github.com/iridakos/goto - brew install goto

    • setup directory aliases and quickly jump to them goto work goto aem63 etc

    • I mostly just like typing goto work

  • n - https://github.com/tj/n - brew install n

    • nodejs version manager

    • commands like n 12 to switch to nodejs 12 or n run 8 index.js to run a file with nodejs 8

    • I just find it a little friendlier than nvm

  • pyenv - https://github.com/pyenv/pyenv - brew install pyenv

    • Don’t use much python, but every time I do versions are an issue. This is a MUST HAVE

      • Seriously you’ll eventually find a tool or something that needs python 3.6 and you have 2.7 or vice versa

  • htop - https://hisham.hm/htop/ - brew install htop

    • Like top but way better

      • Colorful, customizable, mouse support (in iTerm)

  • tldr - https://github.com/tldr-pages/tldr - brew install tldr

    • Like man pages but for people. Shows usage for whatever you search

    • tldr n - shows a few ways you’re likely to use n

    • I honestly haven’t used man or googled CLI usage very much since I started using this

zsh

First, I highly recommend oh-my-zsh - https://ohmyz.sh/

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, etc

If you prefer not to use oh-my-zsh, you can probably still get most of the same functionality, but some things from my ~/.zshrc are going to require tweaking as they rely on it.

One thing not mentioned in my zshrc is zsh-manydots-magic - https://github.com/knu/zsh-manydots-magic - this just does intelligent parsing and expansion of dot usage in commands like cd ... which is the equivalent of cd ../.. - it can follow a lot more dots than that, too. Very handy.

Fun bits from my ~/.zshrc

# Wonderful and powerful zsh theme - https://github.com/romkatv/powerlevel10k
ZSH_THEME="powerlevel10k/powerlevel10k"

# https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins - list & docs
# there are MANY more options, use to your liking
plugins=(zsh-wakatime docker docker-compose extract gitignore node osx sudo urltools)

######################
# ALIASES
#####################
# Alias guide for ZSH
# https://blog.lftechnology.com/command-line-productivity-with-zsh-aliases-28b7cebfdff9
# acs() {
#     apt-cache search $1 | grep $2
# } // acs firstthing secondthing
# alias -s [file-extension]=[name-of-app]
# alias -s json=sublime // always open .json in sublime when just typing file name 

# use "subl" to open sublime from terminal
alias subl=/usr/local/bin/subl
# random bastard operator from hell lines, needs telnet - "brew install telnet"
alias bofhexcuse='telnet towel.blinkenlights.nl 666'
# just in case
alias cd..='cd ..'
# a terminal clock - "brew install tty-clock"
alias termclock='tty-clock -scxtn -C 3'
# Use newer nano than macOS provides - "brew install nano"
alias nano=/usr/local/Cellar/nano/4.9.3/bin/nano
# default rm to interactive
alias rm='rm -i'

######################
# Misc
######################
# goto CLI tool
source ~/.oh-my-zsh/custom/functions/goto.sh
# jenv
PATH=$HOME/bin:/usr/local/bin:$HOME/.jenv/bin:$HOME/Developer/apache-maven-3.6.1/bin:$PATH
eval "$(jenv init -)"
# pyenv
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

###############################
# Bottom things
###############################
# zsh/iTerm shell integration - leave near bottom
source ~/.iterm2_shell_integration.zsh
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle :compinstall filename '/Users/dslaught/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Source goto
[[ -s "/usr/local/share/goto.sh" ]] && source /usr/local/share/goto.sh

Last updated