Wednesday, August 15, 2012

Auto-synchronized development environment with Dropbox

Every now and then, I'm forced to work on a brand new machine. Be it a new laptop at home, a new build farm in the office, or just some temporary workstation of any kind. Since I'm lazy and fond of having computers do stuff for me automatically whenever possible, I found myself thinking why I had to reconfigure Bash, Vim, QtCreator and all sorts of tools I use for work over and over again. Every time you make a change in one of your workstations, you'll have to copy entire files or text sections around in order to get the same configuration in the office, at home and everywhere you wish. By configuration I mean shell aliases and environment variables, editor settings, and also my ~/bin folder that contains loads of useful scripts.

Surely, this can be achieved with a version control system like git, but I wanted something even easier, more automatic and straightforward. Since the cloud is the word of the day, wouldn't it be cool to have all my settings and scripts synchronized automatically with some cloud service? I happen to prefer Dropbox by far for a variety of reasons. So I gave it a try and found out it's trivial to reach the goal. Let's assume for the sake of simplicity that all you want to have available in all your machines, always up-to-date, is ~/.bash_aliases. These are the only required steps to get it done:

  • Install Dropbox. Let's assume the default target directory ~/Dropbox.
  • Create a folder inside it, say home, that relates to your user home directory:
mkdir ~/Dropbox/home
  • Make sure Dropbox is set up to synchronize ~/Dropbox/home
  • Move your Bash configuration to the synchronizable space (i.e. your private cloud). You probably want to rename it so that it doesn't contain the initial dot and stays hidden:
mv ~/.bash_aliases ~/Dropbox/home/bash_aliases
  • Create a symbolic link to this new file from your home directory, and have Bash think it's fetching the configuration from its usual place:
ln -s ~/Dropbox/home/bash_aliases ~/.bash_aliases
That's it. To make it even cooler, I've created a script that performs all the moving and symbolic linking for all files I wish to have synchronized at all times, everywhere. Then, the only task I need to manually repeat every time I add a new machine to my context is the very first one, the installation of Dropbox, making sure that the folder home will be synchronized. All that is missing is running the said script in the end. The script is obviously in the cloud too, in my synchronized ~/bin -> ~/Dropbox/home/bin folder. This works wonderfully for me, I hope you find it useful too.

No comments:

Post a Comment