1+ #! /usr/bin/env bash
2+
13# Easier navigation: .., ..., ...., ....., ~ and -
24alias ..=" cd .."
35alias ...=" cd ../.."
@@ -10,84 +12,87 @@ alias -- -="cd -"
1012alias d=" cd ~/Documents/Dropbox"
1113alias dl=" cd ~/Downloads"
1214alias dt=" cd ~/Desktop"
13- alias p="cd ~/Projects "
15+ alias p=" cd ~/projects "
1416alias g=" git"
15- alias h="history"
16- alias j="jobs"
17- alias v="vim"
18- alias m="mate ."
19- alias s="subl ."
20- alias o="open"
21- alias oo="open ."
2217
2318# Detect which `ls` flavor is in use
2419if ls --color > /dev/null 2>&1 ; then # GNU `ls`
2520 colorflag=" --color"
26- else # OS X `ls`
21+ export LS_COLORS=' no=00:fi=00:di=01;31:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
22+ else # macOS `ls`
2723 colorflag=" -G"
24+ export LSCOLORS=' BxBxhxDxfxhxhxhxhxcxcx'
2825fi
2926
3027# List all files colorized in long format
31- alias l="ls -l ${colorflag}"
28+ alias l=" ls -lF ${colorflag} "
3229
33- # List all files colorized in long format, including dot files
34- alias la="ls -la ${colorflag}"
30+ # List all files colorized in long format, excluding . and ..
31+ alias la=" ls -lAF ${colorflag} "
3532
3633# List only directories
37- alias lsd=' ls -l ${colorflag} | grep "^d"'
34+ alias lsd=" ls -lF ${colorflag} | grep --color=never '^d' "
3835
3936# Always use color output for `ls`
4037alias ls=" command ls ${colorflag} "
41- export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
38+
39+ # Always enable colored `grep` output
40+ # Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage.
41+ alias grep=' grep --color=auto'
42+ alias fgrep=' fgrep --color=auto'
43+ alias egrep=' egrep --color=auto'
4244
4345# Enable aliases to be sudo’ed
4446alias sudo=' sudo '
4547
46- # Gzip-enabled `curl`
47- alias gurl="curl --compressed"
48+ # Get week number
49+ alias week=' date +%V'
50+
51+ # Get macOS Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
52+ alias update=' sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update; sudo gem cleanup'
4853
49- # Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
50- alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm update npm -g; npm update -g; sudo gem update'
54+ # Google Chrome
55+ alias chrome=' /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
56+ alias canary=' /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary'
5157
5258# IP addresses
5359alias ip=" dig +short myip.opendns.com @resolver1.opendns.com"
54- alias localip="ipconfig getifaddr en1 "
55- alias ips="ifconfig -a | grep -o 'inet6\? \(\([0-9]\+\. [0-9]\+\.[0-9]\+\. [0-9]\+\)\|[a-fA-F0-9:]\+\)' | sed -e 's /inet6* // '"
60+ alias localip=" ipconfig getifaddr en0 "
61+ alias ips=" ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\( [0-9]\+\.\)\{3\} [0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub( /inet6? (addr:)? ?/, \"\" ); print } '"
5662
57- # Enhanced WHOIS lookups
58- alias whois="whois -h whois-servers.net "
63+ # Show active network interfaces
64+ alias ifactive= " ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active' "
5965
6066# Flush Directory Service cache
6167alias flush=" dscacheutil -flushcache && killall -HUP mDNSResponder"
6268
6369# Clean up LaunchServices to remove duplicates in the “Open With” menu
6470alias lscleanup=" /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
6571
66- # View HTTP traffic
67- alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
68- alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
69-
7072# Canonical hex dump; some systems have this symlinked
7173command -v hd > /dev/null || alias hd=" hexdump -C"
7274
73- # OS X has no `md5sum`, so use `md5` as a fallback
75+ # macOS has no `md5sum`, so use `md5` as a fallback
7476command -v md5sum > /dev/null || alias md5sum=" md5"
7577
76- # OS X has no `sha1sum`, so use `shasum` as a fallback
78+ # macOS has no `sha1sum`, so use `shasum` as a fallback
7779command -v sha1sum > /dev/null || alias sha1sum=" shasum"
7880
81+ # JavaScriptCore REPL
82+ jscbin=" /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" ;
83+ [ -e " ${jscbin} " ] && alias jsc=" ${jscbin} " ;
84+ unset jscbin;
85+
7986# Trim new lines and copy to clipboard
8087alias c=" tr -d '\n' | pbcopy"
8188
8289# Recursively delete `.DS_Store` files
8390alias cleanup=" find . -type f -name '*.DS_Store' -ls -delete"
8491
85- # ROT13-encode text. Works for decoding, too! ;)
86- alias rot13='tr a-zA-Z n-za-mN-ZA-M'
87-
88- # Empty the Trash on all mounted volumes and the main HDD
89- # Also, clear Apple’s System Logs to improve shell startup speed
90- alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"
92+ # Empty the Trash on all mounted volumes and the main HDD.
93+ # Also, clear Apple’s System Logs to improve shell startup speed.
94+ # Finally, clear download history from quarantine. https://mths.be/bum
95+ alias emptytrash=" sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
9196
9297# Show/hide hidden files in Finder
9398alias show=" defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
@@ -100,9 +105,9 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k
100105# URL-encode strings
101106alias urlencode=' python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
102107
103- # Merge PDF files
104- # Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
105- alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py '
108+ # Merge PDF files, preserving hyperlinks
109+ # Usage: `mergepdf input{1,2,3}.pdf`
110+ alias mergepdf=' gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=_merged.pdf '
106111
107112# Disable Spotlight
108113alias spotoff=" sudo mdutil -a -i off"
@@ -112,9 +117,8 @@ alias spoton="sudo mdutil -a -i on"
112117# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
113118alias plistbuddy=" /usr/libexec/PlistBuddy"
114119
115- # Ring the terminal bell, and put a badge on Terminal.app’s Dock icon
116- # (useful when executing time-consuming commands)
117- alias badge="tput bel"
120+ # Airport CLI alias
121+ alias airport=' /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
118122
119123# Intuitive map function
120124# For example, to list all directories that contain a certain file:
@@ -123,10 +127,22 @@ alias map="xargs -n1"
123127
124128# One of @janmoesen’s ProTip™s
125129for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
126- alias "$method"="lwp-request -m '$method'"
130+ alias " ${ method} " =" lwp-request -m '${ method} '"
127131done
128132
129133# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
130134alias stfu=" osascript -e 'set volume output muted true'"
131- alias pumpitup="osascript -e 'set volume 7'"
132- alias hax="growlnotify -a 'Activity Monitor' 'System error' -m 'WTF R U DOIN'"
135+ alias pumpitup=" osascript -e 'set volume output volume 100'"
136+
137+ # Kill all the tabs in Chrome to free up memory
138+ # [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
139+ alias chromekill=" ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
140+
141+ # Lock the screen (when going AFK)
142+ alias afk=" /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
143+
144+ # Reload the shell (i.e. invoke as a login shell)
145+ alias reload=" exec ${SHELL} -l"
146+
147+ # Print each PATH entry on a separate line
148+ alias path=' echo -e ${PATH//:/\\n}'
0 commit comments