A guide to building a great .bashrc

Zheng Hao Tan
Feb 17, 2016 · 4 min read
Image for post
Image for post

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

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!

Image for post
Image for post
git logo

Git

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

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

-bash: givm: command not found

Then I did this:

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

SSH

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!

Image for post
Image for post

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store