A bash profile quickstart (and how to use it with Ghost)!

We use lots of tools today. Lot's of tricky tools. We have selenium, git, Rspec, PHPUnit, grunt, and of course node stuff. As developers we have to SSH in to all kinds of different places, configure all kinds of things, and most importantly, we have to remember how to do it.

The Problem

So that's the problem. There is no way to remember everything. Let's say by some strange twist of fate you are a freak of science and you happen to actually memorize everything you'll ever need as a dev. This brings us to problem two: even small keystrokes that are needlessly repeated can add up substantially over time. So what's a dev to do?

The Solution: BASH profiles to the rescue.

A bash profile is the thing that has all your basic unix configs setup. System paths, a few global configs, ect..

As a developer, we can leverage this awesome tool to our advantage. Best of all, since it's common on all *nix systems this learning will carry over to multiple systems.

The importance of a good bash profile cannot be understated.

So how does this work? Simple, navigate to your home folder:

cd ~

If you aren't a *nix user, the ~ is a shortcut for the home path

Next, open up your .bash_profile. We will use vim to do this:

sudo vim .bash_profile

In vim you must press either i to begin insert mode so you can type things or shift + a to start inserting at the end of a line.

Now to the fun part: Add your own aliases (aka shortcuts) to the file:

#This is a comment in bash
alias site='cd /var/www/ghost'

When creating an alias in bash the format is: alias keyword='command'.

Make sure to put no space between the keyword and the command. When you are issuing multiple commands in an alias make sure to end each one with a semicolon like so:

#I'm shorthand to start ghost
alias sg='cd /var/www/ghost; npm start'

If you are using a package like forever it might look more like:

alias sg='cd /var/www/ghost; NODE_ENV=production forever start index.js'


You may be thinking, that's nice but what else can I use these for? Well i'm glad you asked! I use them to do things like:

  • Starting and stopping Apache, Nginx, XAMPP, ghost ect.
  • Making shortcuts to commonly needed SSH locations.
  • Shortcuts to my current project or frequently accessed areas.
  • augmenting custom package commands to automatically use features I usually like but don't want to have to type every time.
  • Reloading my bash shell to pick up changes when I change my .bash_profile file.

Let me leave you with a sample of some of these tasks:

#With this you can just type rspec myDir or file #and it will behave as normal but with color.
alias rspec='rspec --color'

#Shorthand bc every keystroke counts
alias gc='git commit'

#Reloading your shell
alias reload='source ~/.bash_profile

If anyone has any questions or comments feel free to reach out on twitter!