Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Command Line Productivity

Command Line Productivity

Held at Vienna.rb on 2018-05-17

Markus Wein

May 17, 2018
Tweet

More Decks by Markus Wein

Other Decks in Programming

Transcript

  1. Git

  2. 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'
  3. ; 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
  4. 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)
  5. ZSH

  6. # 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
  7. # 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
  8. 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))'
  9. 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
  10. # 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='*?[]~&;!$%^<>'
  11. 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
  12. 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 -'
  13. # 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
  14. # 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 }
  15. alias g='git' # mkdir .git/safe in the root of repositories

    you trust export PATH=".git/safe/../../bin:$PATH"
  16. Local zsh settings # use .zshrc.local for settings specific to

    one system [[ -f "${HOME}/.zshrc.local" ]] && source "${HOME}/.zshrc.local"
  17. VIM

  18. 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
  19. " Make ' ' the personal leader key let mapleader

    = "\<Space>" let maplocalleader = "\<Space>"
  20. 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
  21. " 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
  22. " 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%)
  23. 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 <leader>n :call RenameFile()<cr>
  24. • 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