Version Control your .bash_aliases
file using:
- defunkt/gist
- Github Gists
- Bash aliases
I'll use a sample .bash_aliases
file for the tut:
# ~/.bash_aliases
alias hi="echo 'hi'"
alias bye="echo 'bye'"
Next, install defunkt's gist library:
brew install gist
Test to see it's working:
gist -v // gist v4.5.0
Login to your github account through gist
s interactive prompt:
gist --login
Assuming your .bash_aliases
file is in your home directory (~), upload .bash_aliases
as a gist:
gist ~/.bash_aliases
A URL should be returned, like this:
https://gist.github.com/597ffdb59610887fb64ae838a00ee7e6
The numbers after https://gist.github.com/
is the ID
for your new gist. Save this for later, you'll need it in a sec. (If you lose it, just visit the .bash_aliases gist by going to gist.github.com)
Anyway, let's go back to our sample .bash_aliases
file, which currently looks like this:
# ~/.bash_aliases
alias hi="echo 'hi'"
alias bye="echo 'bye'"
We want to be able to easily do the following by typing simple aliases:
- Edit our
.bash_aliases
- Push our updated
.bash_aliases
from our current machine - Pull & source the updated
.bash_aliases
on other machines
Append the following code snippets to .bash_aliases
(be sure to swap out YOUR_GIST_ID
with your actual gist ID
from earlier):
############################
# .bash_aliases management #
############################
// Edit
alias eba="vim ~/.bash_aliases"
This bit adds a section comment (to keep .bash_aliases
tidy). The alias eba
is created for easily editing ~.bash_aliases
in Vim. o0o meta.
Simple - moving on...
// Source changes
alias srcba="source ~/.bash_aliases; echo '.bash_aliases sourced.'"
This one sources the CURRENT .bash_aliases file and echoes a notification.
// Update gist remotely
alias pushba="gist -u YOUR_GIST_ID ~/.bash_aliases; echo '.bash_aliases gist updated.'"
// Pull updated gist to local (warning, will overwrite current ~/.bash_aliases)
alias pullba="gist -r YOUR_GIST_ID > ~/.bash_aliases; echo 'Retrieved updated .bash_aliases file.'; srcba;"
This is the juicy bit. It aliases pushba
and pullba
to the gist
library to update, retrieve, and source your .bash_aliases.
Manually type source ~/.bash_aliases
to enable your new special powers. You can now use the pushba
and pullba
commands on the current machine.
Obviously, though, the point is to use this with other machines. For the initial setup, you'll have to do the manual "copy-and-paste" method for each machine. If I have time, I may create a long one-liner that will do everything. But once everything is configured, your new workflow works like this:
- Edit your .bash_aliases with
eba
(or another editor) and save. - Push changes with
pushba
- To pull and source on another machine (after setup), simply type
pullba
- An additional handy shortcut is now installed:
srcba
, which will source your aliases.