Store frequently used terminal commands in a file

Okay, so I want add a command to my Desktop (Or any convenient location), and whenever I run it I want it to clone the HTML5 boilerplate.

$ git clone git://github.com/paulirish/html5-boilerplate.git

And I'm tired of typing it out all the time. So how could I store my commands in a file?.


Solution 1:

Open your ~/.bashrc and put this at the end:

alias boil='git clone git://github.com/paulirish/html5-boilerplate.git'

or alternatively, this

boil() {
  git clone git://github.com/paulirish/html5-boilerplate.git
}

From now on, in every new terminal you can use the command boil as an alternative to your long command.

The second version is to prefer, because is more flexible being able to accept and manage parameter, for example if you define

boil() {
  [[ -z "$1" ]] && set "github.com"
  git clone git://"$1"/paulirish/html5-boilerplate.git
}

you can easily change server, if there are mirror.

# without a parameter, the function will use a default
boil
# override the default providing explicitly a server parameter
boid othergit.com

It is only an example, your fantasy surely will generate something more useful.

Obviously you can add as many functions as you need.