A guide to building a great .bashrc

Zheng Hao Tan
4 min readFeb 17, 2016

--

Have you wondered how much time do you spend on the terminal? Running a Python script or trying to stash the changes you made (or fix broken code) on Git? Maybe you have some daemon process running that you wanna kill or even ssh into your favorite Linux box that is sitting on the other side of the world.

We programmers are lazy, so let’s bring laziness to a whole new level, shall we?

First Things First

If you guys need a refresher on where to find or use the.bashrc, it’s normally located in ~, your home directory. This is where bash will try to find your settings and load them whenever the terminal is opened.

Wait… why is there no .bashrcin my home directory?

What’s with ~/.bash_profile?

If you’re using a Mac, chances are that you will type these in your ~/.bash_profile as opposed to your ~/.bashrc.

There is a simple workaround for using .bashrc on MacOS: adding this snippet in .bash_profile and making your configs in a new .bashrc file.

# Put this in your .bash_profile file.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

Here’s a good guide written by Josh Staiger a while back that explain this more thoroughly.

Common Commands

alias q=’exit’alias c=’clear’alias h=’history’alias cs=’clear;ls’alias p=’cat’alias pd=’pwd’alias lsa=’ls -a’alias lsl=’ls -l’alias pd=’pwd’alias t=’time’alias k='kill'alias null=’/dev/null’

I dislike typing exit, so I did qand it closes the terminal.

I dislike typing the word clear, so I hit cand it’s done.

Same goes for the other commands, as I try to squeeze out these commands from as little characters typed as possible.

Directories

alias home='cd ~'alias root='cd /'alias dtop='cd ~/Desktop'alias dbox='cd ~/Dropbox'alias box='cd ~/Box\ Sync'alias gdrive='cd ~/Google\ Drive'# Common project directoriesalias cppprojects='cd ~/Dropbox/Projects/C++Projects'alias cprojects='cd ~/Dropbox/Projects/CProjects'alias pythonprojects='cd ~/Dropbox/Projects/PythonProjects'alias goprojects='cd ~/Dropbox/Projects/GoProjects'alias rustprojects='cd ~/Dropbox/Projects/RustProjects'alias o=openalias ..='cd ..'alias ...='cd ..; cd ..'alias ....='cd ..; cd ..; cd ..'

I’ve learned to appreciate the o (open) command the most on a Mac OS X since I get to whichever files I want and have them opened in the configured default applications.

NOTE: on Ubuntu, do this instead of open:

alias o=xdg-open

I also hate having to move up 2 or 3 directories up but still not having to type cd ~/bla/blabla/blablabla. So I shall let the dots do the talking!

git logo

Git

I believe you use version control systems really often, and my favorite one is Git. Here’s a simple example on how I made it “easier” to use.

alias g=’git’alias st=’git status’alias com=’git commit -m’alias clone=’git clone’alias sth=’git stash’alias lg=’git log’alias u=’git add -u’alias all=’git add .’

Need a quick commit for all modified files? Just do this:

ucom ‘updated code’

Profit.

Program Aliases

I only use these on my Mac, so I have them aliased to the common commands that you see on the Internet.

alias gcc='gcc-6'alias g++='g++-6'alias tar='gtar'alias python='python3'alias pip='pip3'# Shortcuts to vimrc and bashrcalias vimrc='vim ~/.vimrc'alias bashrc='vim ~/.bash_profile'alias loadbash='source ~/.bash_profile'# Ctags.
alias gentags='ctags -R .'

UNIX Command Options

# Let there be color in grep!
export GREP_OPTIONS=' — color=auto'
# Set Vim as my default editor
export EDITOR=vim

Toolchain Stuff

# ARM toolchainexport PATH=$PATH:~/toolchains/gcc-arm-none-eabi-4_9–2015q3/bin# MSP toolchainexport PATH=$PATH:~/toolchains/ti/gcc/bin

Typos

Sometimes, you get really tired of all the typos in your life. And then the terminal shoots you with this:

-bash: givm: command not found

Then I did this:

alias givm='gvim'alias cta='cat'alias gerp='grep'alias sl='ls'

SSH

Missing that Linux box on the other side of the world?

alias myec2box=’ssh <insert whatever here>'alias pythonserver=’python -m SimpleHTTPServer 8000'

Think about how long you spend trying to type the word gitas opposed to g. That’s 2 extra letters to deal with for every time you try to do something about it. Let’s say you use the git command 20 times a day and you do ginstead of git. That’s at least 40 less characters typed everyday, or 280 every week!

There are many more things that you can do by having these on your .bashrc, such as a one line command that helps you set up your computer to your liking.

Or maybe a command that helps run a shell script to brew you some coffee in the morning.

Here’s where you can find my latest .bashrc .

Do the right thing. Build a great .bashrc for yourself.

Bonus: When you have nothing better to do

alias meow='cat'

Yay! You made it to the very end of this post. Here’s a picture of a cat!

This is my first blog post, and I hope that you like it as much as I do. I am still learning new technologies, so if you find something up here that is incorrect, please leave a comment or shoot me an email :)

Update:

I’ve moved on to using zsh. Oh My Zsh is just too good. Nevertheless, all the commands above still work and can easily be ported over to your ~/.zshrc file.

--

--

Zheng Hao Tan

Founder / CEO of Cellulose. Angel investor. ex Lexer (YC S22), Cruise, DriveAI, Hologram.