Slide 1

Slide 1 text

Command Line Productivity

Slide 2

Slide 2 text

Why?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Learn your tools

Slide 5

Slide 5 text

Keep a (hand-written!) cheat sheet

Slide 6

Slide 6 text

LaunchBar

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Put your dotfiles in Git gitlab.com/nuclearsquid/dotfiles

Slide 10

Slide 10 text

Comment everything extensively

Slide 11

Slide 11 text

pbcopy & pbpaste

Slide 12

Slide 12 text

Brewfile brew bundle

Slide 13

Slide 13 text

Git

Slide 14

Slide 14 text

Machine-specific config [include] path = ~/.gitconfig.private

Slide 15

Slide 15 text

Git aliases

Slide 16

Slide 16 text

Only add the changes you want git config --global alias.ap 'add --patch'

Slide 17

Slide 17 text

Diffing git config --global alias.d 'diff --ignore-all-space' git config --global alias.dc 'diff --cached --ignore-all-space' git config --global alias.wd 'diff --word-diff="color"' git config --global alias.wdc 'diff --word-diff="color" --cached'

Slide 18

Slide 18 text

git stash

Slide 19

Slide 19 text

; Inspect history in various ways news = log -p HEAD@{1}..HEAD@{0} ; Show compact history l = "!git log -10 --graph --pretty='tformat:%C(yellow)%h{%C(green)%ar\ {%C(bold blue)%an{%C(red)%d%C(reset) %s' $* | column -t -s '{' | less -FXRS" ; Show commit log using graph notation lg = log --color --graph --pretty=format:'%Cred%h%Creset \ -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \ --abbrev-commit --date=relative ; List commits showing changed files ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" \ --decorate --numstat

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

git-rerere

Slide 23

Slide 23 text

Emacs editor commands • Ctrl-a (go to beginning of line) • Ctrl-e (go to end of line) • Ctrl-r (search backwards through history) • Alt-f (move cursor forward 1 word) • Alt-b (move cursor backwards 1 word)

Slide 24

Slide 24 text

ZSH

Slide 25

Slide 25 text

# Via https://kev.inburke.com/kevin/profiling-zsh-startup-time/ PROFILE_STARTUP=${PROFILE_STARTUP:-false} if [[ "$PROFILE_STARTUP" == true ]]; then PS4=$'%D{%M%S%.} %N:%i> ' exec 3>&2 2>$HOME/tmp/startlog.$$ setopt xtrace prompt_subst fi # Your zshrc here… if [[ "$PROFILE_STARTUP" == true ]]; then unsetopt xtrace exec 2>&3 3>&- fi

Slide 26

Slide 26 text

# Enable Ctrl-x-e to edit command line autoload -U edit-command-line zle -N edit-command-line bindkey '^xe' edit-command-line bindkey '^x^e' edit-command-line

Slide 27

Slide 27 text

Auto-complete ssh hosts # Auto-completion for ssh hosts zstyle -e ':completion::*:hosts' hosts \ 'reply=($(sed -e "/^#/d" -e "s/ .*\$//" -e "s/,/ /g" /etc/ssh_known_hosts(N) \ ~/.ssh/known_hosts(N) 2>/dev/null | \ xargs) $(grep \^Host ~/.ssh/config(N) | \ cut -f2 -d\ 2>/dev/null | xargs))'

Slide 28

Slide 28 text

Zsh Prompt # Combined left and right prompt configuration. local smiling_face=$'\U1F60A' local frowning_face=$'\U1F914' local smiley="%(?,%{%F{green}%}${smiling_face}%{%f%},${frowning_face}%{%F{red}%}%{%f%})" PROMPT='%m %B%F{red}::%f%b %B%F{green}%3~%f%b ${smiley}%{$reset_color%} %B%F{blue}%(0!.#.»)%b%f ' RPROMPT='' if type pretty-git-prompt > /dev/null; then RPROMPT='$(pretty-git-prompt)' fi # Put rbenv version info on the right side, if rbenv is available if type rbenv > /dev/null; then RPROMPT="%F{white}\$(rbenv version-name)%f $RPROMPT"; fi

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

autoload -U zmv $ zmv 'Screenshot (*).png' '$1.png'

Slide 31

Slide 31 text

REPORTTIME=10

Slide 32

Slide 32 text

# By default, zsh considers many characters part of a word (e.g., _ and -). # Narrow that down to allow easier skipping through words via M-f and M-b. export WORDCHARS='*?[]~&;!$%^<>'

Slide 33

Slide 33 text

Exa (ls replacement) ############################################################################## # Custom aliases ############################################################################## # Replace `ls` with `exa`, if it's available if type exa > /dev/null then alias ls='exa --color=auto' alias la='exa --color=auto --all --group' alias lla='exa --color=auto --all --group --long' alias lt='exa --color=auto --all --group --tree --level=2' alias l='exa --color=auto --group --long' else alias ls='ls -hFbC' alias la='ls -hFA' alias lla='ls -lhFA' alias lt='echo This command requires exa installed' alias l='ls -lhFbC' fi

Slide 34

Slide 34 text

alias '..'='cd ..' # The -g makes them global aliases, so they're expaned even inside commands alias -g ...='../..' alias -g ....='../../..' alias -g .....='../../../..' alias -g ......='../../../../..' alias -g .......='../../../../../..' # Aliases '-' to 'cd -' alias -- -='cd -'

Slide 35

Slide 35 text

# chmod alias rw-='chmod 600' alias rwx='chmod 700' alias r--='chmod 644' alias r-x='chmod 755'

Slide 36

Slide 36 text

# Use Ctrl-Z to switch back to vim too! # Nicked from https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/ fancy-ctrl-z () { if [[ $#BUFFER -eq 0 ]]; then BUFFER="fg" zle accept-line else zle push-input zle clear-screen fi } zle -N fancy-ctrl-z bindkey '^Z' fancy-ctrl-z

Slide 37

Slide 37 text

# mkdir, cd into it (via http://onethingwell.org/post/586977440/mkcd-improved) function mkcd () { mkdir -p "$*" && cd "$*" }

Slide 38

Slide 38 text

alias now='ruby -e "puts Time.now.utc.to_i"' alias uuid='python -c "import uuid; print uuid.uuid1()"'

Slide 39

Slide 39 text

# Via https://github.com/garybernhardt/dotfiles/blob/master/.zshrc # Switch projects function p() { local proj=$(ls ~/Projects | selecta) if [[ -n "$proj" ]]; then cd ~/Projects/$proj fi } # Switch work function w() { local work=$(ls ~/Work | selecta) if [[ -n "$work" ]]; then cd ~/Work/$work fi } # Edit a note function n() { # Need to use -L, since Notes and Research are usually symlinked into some sort of syncing service local note=$(find -L ~/Notes ~/Research | selecta) if [[ -n "$note" ]]; then (cd ~/Notes && vi "$note") fi }

Slide 40

Slide 40 text

# Bundler: alias be='bundle exec' alias b='bundle'

Slide 41

Slide 41 text

alias g='git' # mkdir .git/safe in the root of repositories you trust export PATH=".git/safe/../../bin:$PATH"

Slide 42

Slide 42 text

Local zsh settings # use .zshrc.local for settings specific to one system [[ -f "${HOME}/.zshrc.local" ]] && source "${HOME}/.zshrc.local"

Slide 43

Slide 43 text

VIM

Slide 44

Slide 44 text

Break up your config source $HOME/.vim/basics.vim source $HOME/.vim/bindings.vim source $HOME/.vim/editing.vim source $HOME/.vim/extensions.vim source $HOME/.vim/snippets.vim if filereadable($HOME . "/.vimrc.local") source ~/.vimrc.local endif

Slide 45

Slide 45 text

" Make ' ' the personal leader key let mapleader = "\" let maplocalleader = "\"

Slide 46

Slide 46 text

" Yank and paste with the system clipboard set clipboard^=unnamed,unnamedplus

Slide 47

Slide 47 text

set number " Show line numbers set relativenumber " Show relative line numbers set numberwidth=5 " How many columns to use for the line number augroup relativenumbers autocmd! " Show absolute line numbers in insert mode, relative line numbers otherwise autocmd InsertEnter * :set norelativenumber autocmd InsertLeave * :set relativenumber augroup END

Slide 48

Slide 48 text

" Sane searching set hlsearch " Hilight search term set showmatch " Show matching brackets set incsearch " ... dynamically as they are typed " make /-style searches case-sensitive only if " there is a capital letter in the search expression set ignorecase set smartcase

Slide 49

Slide 49 text

" Clear statusline set statusline= " Current file set statusline+=%f " modified flag set statusline+=\ %2*%m " help buffer flag set statusline+=\ %1*%h " Fugtive status set statusline+=%#warningmsg# set statusline+=%{fugitive#statusline()} set statusline+=%* " Readonly flag set statusline+=%r " Switch to right side set statusline+=%= set statusline+=[ " File encoding set statusline+=%{&encoding} " File format set statusline+=\ %{&fileformat} " Detected file type set statusline+=\ %{strlen(&filetype)?&filetype:'none'} set statusline+=] " Position in file set statusline+=\ %12.(%c:%l/%L%)

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

" Via https://twitter.com/tenderlove/status/986273578499952641 nnoremap wtf oputs "#" * 90puts callerputs "#" * 90

Slide 52

Slide 52 text

function! RenameFile() let old_name = expand('%') let new_name = input('New file name: ', expand('%'), 'file') if new_name != '' && new_name != old_name exec ':saveas ' . new_name exec ':silent !rm ' . old_name redraw! endif endfunction map n :call RenameFile()

Slide 53

Slide 53 text

Ctags

Slide 54

Slide 54 text

"Go to the definition of the word under cursor"

Slide 55

Slide 55 text

Tim Pope's plugins

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

• fugitive.vim (Working with git) • vim-commentary (Easily comment out lines) • vim-surround (Easily surround text with braces) • vim-unimpaired (Various useful things) • ruby.vim & rails.vim (Working with Rails) • vim-bundler

Slide 59

Slide 59 text

CtrlP

Slide 60

Slide 60 text

Your computer should serve you

Slide 61

Slide 61 text

You shouldn't need to remember arcane stuff (unless it's faster)

Slide 62

Slide 62 text

Write aliases Write scripts

Slide 63

Slide 63 text

Watch Screencasts

Slide 64

Slide 64 text

Investment in productivity will pay off a lot later on

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

!" squidlinks.ironsquid.net nuclearsquid.com gitlab.com/nuclearsquid/dotfiles