Aliasing All the Things to Improve Your Development Experience

If you're in programming for the long run, alias all the things. Trust me, it's going to save your fingers and improve your day-to-day life as a developer.

I've been in web development for close to 15 years, I'm still surprised how infrequently people use aliases. I use aliases for everything - I even have a bash function to create new aliases on the fly.

As a developer, you are going to be typing... a lot. Help yourself out by aliasing all the things you type over and over again. Let the computer work for you - that's why we made them, right?

What is my purpose?

What is an alias?


I'm specifically talking about terminal commands here, be it bash or zsh, or even git. Aliases are really simple to configure and will save you days of typing over your career, your fingers will thank you.

How do I set up aliases?


I personally have a single file for all of my zsh aliases (works the same for bash) where I store everything related to aliasing. In my zsh config file I source this file which makes my aliases accessible when I start a new terminal session.

First let's create the aliases file and source it in our .zshrc or .bashrc file.

touch ~/.aliases

source $HOME/.aliases

I recommend also setting up your EDITOR if you haven't already done that. I use macvim locally and vi while ssh'ing so I use the following snippet at the top of my .zshrc file

# ~/.zshrc
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR=vi
else
  # the -c flag will run the following command when opening the new macvim window
  # the command will return us to iTerm after we close the macvim window
  export EDITOR='mvim -f -c "au VimLeave * !open -a iTerm"'
fi

Now that we have that set up let's set up some aliases!

First thing I suggest is adding a function to add aliases on the fly
When you notice you've typed the same command over and over again just pull the lever!
# ~/.aliases
addalias() {
  echo 'alias '$1'="'$2'"' >> ~/.aliases
  source ~/.aliases
}

This is a pretty basic function, it just takes 2 arguments, appends them to your aliases file and then sources the file to include the new alias in your current terminal session. e.g.

addalias rr "bin/rails routes"

Now we can call

rr | grep users

Which will find all the routes which include the substring, users.

Using addalias after typing the same command over and over again while debugging or doing some repetitive task is extremely satisfying

Some of my most used aliases


# ~/.aliases
alias la='ls -a'
alias ll='ls -al'

alias zshconfig="$EDITOR ~/.zshrc"
alias ohmyzsh="$EDITOR ~/.oh-my-zsh"
alias vimconfig="$EDITOR ~/.vimrc"
alias sshconfig="$EDITOR ~/.ssh/config"
alias aliases="$EDITOR ~/.aliases"

alias g='git'
alias gx="gitx"

alias push="git push origin HEAD"
alias ppr="push && git pull-request -c"
alias pprm="push && git pull-request -c -m"
alias pr="git pull-request -c"
alias prm="git pull-request -c -m"

alias b='bundle'
alias bi='b install'
alias bu='b update'
alias be='b exec'

alias spring="be spring"
alias sidekiq="bundle exec sidekiq"
alias rspec='be rspec --no-profile'
alias rspecp='be rspec'
alias wds='bin/webpack-dev-server'
alias guard='be guard'

Aliasing git commands


In my experience most developers are aware of Git's capabilities but somehow overlook the aliasing abilities. Maybe it's because most people use a GUI - I don't know, but for me Git aliases are a must. Here are some of mine

# ~/.gitconfig
[alias]
	a  = add
	aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
	b  = branch
	c  = commit
	cm = commit -m
	ca = commit -C HEAD --amend
	co = checkout
	cp = cherry-pick
	dt = difftool
	l = log
	mt = mergetool
	p  = push
	pr = pull-request -m
	ra = rebase --abort
	rc = rebase --continue
	ri = rebase -i
	rs = rebase --skip
	s  = status

Using aliases


I use most of these daily, after a while they become muscle memory. As a ruby developer I spend a lot of time in the terminal, both in the rails console and committing my work. With aliases my commands are a lot shorter e.g.

git check-out -b chore/new_branch
g co -b chore/new_branch

bin/rails c
r c

git status
g s

gitx
gx

I also use them to replace knowledge I struggle to internalize. For some reason I can never remember where the ssh config is stored, but I can easily remember an alias so I created sshconfig and now I don't need to look it up every time I want to modify the file.

alias sshconfig="$EDITOR ~/.ssh/config"

If this is something that interests you I highly recommend learning some bash scripting too, it's impressive how far you can get with a little knowledge.
Like 2 likes
Joe Woodward
I'm Joe Woodward, a Ruby on Rails fanatic working with OOZOU in Bangkok, Thailand. I love Web Development, Software Design, Hardware Hacking.
Share:

Join the conversation

This will be shown public
All comments are moderated

Get our stories delivered

From us to your inbox weekly.