A few more of my favorite Bash aliases

[Tweet : ADN : nvALT]

I love my aliases. It’s part of the reason I need a better dotfile management setup — porting them to any server environment I’m working on is a must for my sanity. I thought I’d share a few of the ones I find handy, especially in OS X environments.

Chrome

Chrome is still my browser of choice for most purposes, but it has a couple of quirks. First, dragging an html file to it doesn’t seem to open a new tab or load the file in the current tab. It just does nothing. A quick alias using open is my workaround:

alias chrome="open -a \"Google Chrome\""

Next, it frequently loads up with the fonts all wonky. This is probably due to font conflicts on my system, but it happens to me on multiple machines and drives me crazy. Here are a couple of aliases I use to restart the font server and launch Chrome, solving the issue.

alias atskill="atsutil server -shutdown && sleep 5 && atsutil server -ping"
alias atchrome="atskill && chrome"

The combination of the the two allow me to just run atchrome to start it up fresh. I have a more complex one that gently quits chrome (osascript), restarts the server and then launches Chrome with a few command line flags, but that one has dependencies and personal tweaks that aren’t very useful to others.

Scripting

I write a lot of scripts, so chmod a+x is a frequent friend. I also have a few shortcuts for editing some shell files. They’re set to use my $EDITOR1 variable but could be modified for any editor:

# make executable
alias ax="chmod a+x"
# edit .bash_profile
alias bp="$EDITOR ~/.bash_profile"
# edit keybindings.dict
alias kb="$EDITOR ~/Library/KeyBindings/DefaultKeyBinding.dict"
# reload your bash config
alias src="source ~/.bash_profile"

I would also highly recommend checking out editscript, my tool for quickly locating my various scripts and editing them.

Git

Most of my git aliases are actually “git aliases,” created in my global .gitconfig. These are a few that I find handy on their own:

# add and remove new/deleted files from git index automatically
alias gitar="git ls-files -d -m -o -z --exclude-standard | xargs -0 git update-index --add --remove"
# git push
alias gpd="git push origin develop"
alias gpm="git push origin master"
# Remove git from a project
alias ungit="find . -name '.git' -exec rm -rf {} \;"

Misc

A few miscellaneous commands with a range of usefulness:

#copy output of last command to clipboard
alias cl="fc -e -|pbcopy"

# top
alias cpu='top -o cpu'
alias mem='top -o rsize' # memory

# copy the working directory path
alias cpwd='pwd|tr -d "\n"|pbcopy'

# DNS (with update thanks to @blanco)
alias flush="sudo killall -HUP mDNSResponder"

# share history between terminal sessions
alias he="history -a" # export history
alias hi="history -n" # import history

# Get your current public IP
alias ip="curl icanhazip.com"

# ls better
alias la="ls -aF"
alias ld="ls -ld"
alias ll="ls -l"
alias lt='ls -At1 && echo "------Oldest--"'
alias ltr='ls -Art1 && echo "------Newest--"'

# mount all connected Firewire disks
alias mountall='system_profiler SPFireWireDataType | grep "BSD Name: disk.$" | sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil mountDisk $i; done)'
# unmount them all
alias unmountall='system_profiler SPFireWireDataType | grep "BSD Name: disk.$" | sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil unmountDisk $i; done)'

# recursively delete Dropbox conflicted files
alias rmdbc="find . -name *\ \(*conflicted* -exec rm {} \;" 

# mute the system volume
alias stfu="osascript -e 'set volume output muted true'"

# time machine log
alias tmlog="syslog -F '\$Time \$Message' -k Sender com.apple.backupd-auto -k Time ge -30m | tail -n 1"

# trim newlines
alias tn='tr -d "\n"'

# list TODO/FIX lines from the current project
alias todos="ack -n --nogroup '(TODO|FIX(ME)?):'"

# create a Taskpaper todo file in the current folder
alias tp='touch todo.taskpaper && open -a "Taskpaper" todo.taskpaper'

# interactive fasd
alias zi="fasd -e cd -i"
  1. See my post on a multi-purpose $EDITOR variable for some ideas.

Ryan Irelan has produced a series of shell trick videos based on BrettTerpstra.com posts. Readers can get 10% off using the coupon code TERPSTRA.