# Easier directory navigation alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." alias ~="cd ~" # Detect which `ls` flavor is in use if ls --color > /dev/null 2>&1; then # GNU `ls` colorflag="--color" else # OS X `ls` colorflag="-G" fi # Use exa in place of ls if installed if command -v exa >/dev/null 2>&1; then alias l="exa -l --git" alias ls="exa" alias la="exa -la --git" alias lt="exa -lRT --git" alias lta="exa -laRT --git" else # Use coloured output for `ls` alias ls="command ls ${colorflag}" alias l="ls -lF ${colorflag}" alias la="ls -laF ${colorflag}" alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" fi # Shortcuts for Cargo commands if command -v cargo >/dev/null 2>&1; then alias cb='cargo build' alias cr='cargo run' alias ct='cargo test' fi # Enable aliases to be sudo’ed alias sudo='sudo ' # Prefer coloured grep alias grep="grep --color=auto" # Gzip-enabled `curl` alias gurl='curl --compressed' # Get week number alias week='date +%V' # Stopwatch alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' # IP addresses alias ip="dig +short myip.opendns.com @resolver1.opendns.com" alias localip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'" # Flush Directory Service cache alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder" # Clean up LaunchServices to remove duplicates in the “Open With” menu alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder" # View HTTP traffic alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'" alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" # Canonical hex dump; some systems have this symlinked command -v hd > /dev/null || alias hd="hexdump -C" # OS X has no `md5sum`, so use `md5` as a fallback command -v md5sum > /dev/null || alias md5sum="md5" # OS X has no `sha1sum`, so use `shasum` as a fallback command -v sha1sum > /dev/null || alias sha1sum="shasum" && alias sha256sum="shasum -a 256" # Trim new lines and copy to clipboard alias c="tr -d '\n' | pbcopy" # Recursively delete `.DS_Store` files alias cleanup="find . -type f -name '*.DS_Store' -ls -delete" # ROT13-encode text. Works for decoding, too! ;) alias rot13='tr a-zA-Z n-za-mN-ZA-M' # Empty the Trash on all mounted volumes and the main HDD # Also, clear Apple’s System Logs to improve shell startup speed alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl" # Show/hide hidden files in Finder alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" alias hidefiles="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder" # Hide/show all desktop icons (useful when presenting) alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder" alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" # URL-encode strings alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' # Merge PDF files # Usage: `mergepdf -o output.pdf input{1,2,3}.pdf` alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py' # PlistBuddy alias, because sometimes `defaults` just doesn’t cut it alias plistbuddy="/usr/libexec/PlistBuddy" # Intuitive map function # For example, to list all directories that contain a certain file: # find . -name .gitattributes | map dirname alias map="xargs -n1" # Lock the screen (when going AFK) alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend" # Launch screen saver instantly alias screensaver="open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app" # Reload the shell (i.e. invoke as a login shell) alias reload="exec $SHELL -l" # Ping google.com to test connection alias pg="ping -qo google.com" # Shortcut to quickly time Python snippets alias timepy="python -m timeit" # Shorter dotfile update command alias dot="dotfiles" # Pasteboard length alias pbc="pbpaste | wc -c"