During our fantastical Lunch and Learn at ChaiOne, we went over customizing bash using aliases and functions. These little tools make normal command line mortals into command line gods… or at least demi-gods.
If you are new to Macs and other Unix based systems, like I am, then what I am about to share will be new to you. It was new to me until today. And for those Unix gurus, if I describe something incorrectly please let me know.
First of all there is a file called .bashrc in your home directory ( ~ ). This file is loaded anytime you run a command script or open a terminal window. In this file we can add aliases, functions, and other customizations for our command line.
With an alias I can create a shortcut ‘g’ for ‘git status’.
1
|
|
Now I can just type ‘g’ to run ‘git status’.
I can use a function to create a more robust shortcut. For example, I can create a shortcut for ‘git push’. In this function by default I push to ‘origin master’ but if I provide an argument it will push to ‘$argument master’.
1 2 3 4 5 6 7 8 |
|
gpush => git push origin master
gpush heroku => git push heroku master
Once you add the alias or function to your .bashrc, you can reload the file using
1
|
|
And there is a shortcut for source ( . ) So you can use
1
|
|
Now you know how to create aliases and functions. I must admit, I think its pretty damn cool. This coming from the guy that a year ago was hesitant to use git on the command line.