Bash aliases are one of the truly great timesavers when working in Unix/Linux. I’ve picked up quite a few aliases from others on my travels around the Internet and many have become second nature. Moreover, in quite a few cases, I’ve (almost) forgotten the original command!
Lately, I’ve done a lot of development work using Vagrant and, honestly, I’d never want to go back to trying to set up development environments on individual machines, since Vagrant makes standardization so simple. At the same time, even though my Vagrant box is pretty well standardized, everyone probably has their on bash aliases that they like to use. So, here’s how to have the best of both worlds!
What we want to do is provide a simple way to grab our bash aliases from Github and apply them from most any machine.
- Put your bash aliases (or any other bash settings!) into a file a file named
.bash_aliasand add this file to your Github account. The conventional practice is to put these in a repository named
- Determine the “raw git” URL to your new
.bash_aliason Github. Essentially, this URL starts with
https://raw.githubusercontent.com/and then follows the standard pattern for Github URLs of your username, repository name, branch, and file name. For example, my
.bash_aliases“raw” URL is
- Now, here’s where all of the magic happens! When you want to apply your aliases on a machine that you are logged into, such as a Vagrant box, just run this command at the shell:
curl https://raw.githubusercontent.com/TimothyDJones/dotfiles/master/.bash_aliases -o /tmp/.bash_aliases; source /tmp/.bash_aliases
Viola! All of your aliases are now available on this machine. And, of course, you can add this command to your
.bash_profileon that machine, so that it will run automatically everytime you log in.
Note: When dealing with your Unix/Linux configuration files (“dotfiles”), it is very important to pay attention to the line endings of your files. Windows and Unix/Linux use different conventions. The best way to account for this is to set the
autocrlf parameter in the
dotfile repository on your workstation by running:
git config core.autocrlf true