1+ #! /usr/bin/env bash
2+
13# Easier navigation: .., ..., ...., ....., ~ and -
24alias ..=" cd .."
35alias ...=" cd ../.."
@@ -12,83 +14,85 @@ alias dl="cd ~/Downloads"
1214alias dt=" cd ~/Desktop"
1315alias p=" cd ~/projects"
1416alias g=" git"
15- alias h="history"
16- alias j="jobs"
1717
1818# Detect which `ls` flavor is in use
1919if ls --color > /dev/null 2>&1 ; then # GNU `ls`
2020 colorflag=" --color"
21- 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`
2223 colorflag=" -G"
24+ export LSCOLORS=' BxBxhxDxfxhxhxhxhxcxcx'
2325fi
2426
2527# List all files colorized in long format
2628alias l=" ls -lF ${colorflag} "
2729
28- # List all files colorized in long format, including dot files
29- alias la="ls -laF ${colorflag}"
30+ # List all files colorized in long format, excluding . and ..
31+ alias la=" ls -lAF ${colorflag} "
3032
3133# List only directories
3234alias lsd=" ls -lF ${colorflag} | grep --color=never '^d'"
3335
3436# Always use color output for `ls`
3537alias ls=" command ls ${colorflag} "
36- 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'
3744
3845# Enable aliases to be sudo’ed
3946alias sudo=' sudo '
4047
41- # Gzip-enabled `curl`
42- alias gurl='curl --compressed'
43-
4448# Get week number
4549alias week=' date +%V'
4650
47- # Stopwatch
48- alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date '
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 '
4953
50- # Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
51- alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm update npm -g; npm update -g; sudo gem update --system; 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'
5257
5358# IP addresses
5459alias ip=" dig +short myip.opendns.com @resolver1.opendns.com"
55- alias localip="ipconfig getifaddr en1 "
60+ alias localip=" ipconfig getifaddr en0 "
5661alias ips=" ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\" ); print }'"
5762
58- # Enhanced WHOIS lookups
59- 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' "
6065
6166# Flush Directory Service cache
6267alias flush=" dscacheutil -flushcache && killall -HUP mDNSResponder"
6368
6469# Clean up LaunchServices to remove duplicates in the “Open With” menu
6570alias lscleanup=" /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
6671
67- # View HTTP traffic
68- alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
69- alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
70-
7172# Canonical hex dump; some systems have this symlinked
7273command -v hd > /dev/null || alias hd=" hexdump -C"
7374
74- # OS X has no `md5sum`, so use `md5` as a fallback
75+ # macOS has no `md5sum`, so use `md5` as a fallback
7576command -v md5sum > /dev/null || alias md5sum=" md5"
7677
77- # OS X has no `sha1sum`, so use `shasum` as a fallback
78+ # macOS has no `sha1sum`, so use `shasum` as a fallback
7879command -v sha1sum > /dev/null || alias sha1sum=" shasum"
7980
81+ # JavaScriptCore REPL
82+ jscbin=" /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" ;
83+ [ -e " ${jscbin} " ] && alias jsc=" ${jscbin} " ;
84+ unset jscbin;
85+
8086# Trim new lines and copy to clipboard
8187alias c=" tr -d '\n' | pbcopy"
8288
8389# Recursively delete `.DS_Store` files
8490alias cleanup=" find . -type f -name '*.DS_Store' -ls -delete"
8591
86- # ROT13-encode text. Works for decoding, too! ;)
87- alias rot13='tr a-zA-Z n-za-mN-ZA-M'
88-
89- # Empty the Trash on all mounted volumes and the main HDD
90- # Also, clear Apple’s System Logs to improve shell startup speed
91- 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'"
9296
9397# Show/hide hidden files in Finder
9498alias show=" defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
@@ -101,9 +105,9 @@ alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && k
101105# URL-encode strings
102106alias urlencode=' python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
103107
104- # Merge PDF files
105- # Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
106- 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 '
107111
108112# Disable Spotlight
109113alias spotoff=" sudo mdutil -a -i off"
@@ -113,9 +117,8 @@ alias spoton="sudo mdutil -a -i on"
113117# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
114118alias plistbuddy=" /usr/libexec/PlistBuddy"
115119
116- # Ring the terminal bell, and put a badge on Terminal.app’s Dock icon
117- # (useful when executing time-consuming commands)
118- alias badge="tput bel"
120+ # Airport CLI alias
121+ alias airport=' /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
119122
120123# Intuitive map function
121124# For example, to list all directories that contain a certain file:
@@ -124,16 +127,12 @@ alias map="xargs -n1"
124127
125128# One of @janmoesen’s ProTip™s
126129for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
127- alias "$method"="lwp-request -m '$method'"
130+ alias " ${ method} " =" lwp-request -m '${ method} '"
128131done
129132
130- # Make Grunt print stack traces by default
131- command -v grunt > /dev/null && alias grunt="grunt --stack"
132-
133133# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
134134alias stfu=" osascript -e 'set volume output muted true'"
135- alias pumpitup="osascript -e 'set volume 7'"
136- alias hax="growlnotify -a 'Activity Monitor' 'System error' -m 'WTF R U DOIN'"
135+ alias pumpitup=" osascript -e 'set volume output volume 100'"
137136
138137# Kill all the tabs in Chrome to free up memory
139138# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
@@ -143,7 +142,7 @@ alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v exten
143142alias afk=" /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
144143
145144# Reload the shell (i.e. invoke as a login shell)
146- alias reload="exec $SHELL -l"
145+ alias reload=" exec ${ SHELL} -l"
147146
148- # Faster npm for europeans
149- command -v npm > /dev/null && alias npme="npm --registry http://registry.npmjs.eu"
147+ # Print each PATH entry on a separate line
148+ alias path= ' echo -e ${PATH//:/\\n} '
0 commit comments