Syncing dotfiles using your MobileMe iDisk

Posted by Sheldon Finlay on April 11, 2009

If you are developing on a Mac, you no doubt use dotfiles. If you are like me, you are constantly tweaking your dotfiles, adding in new aliases and functions or whatever to help streamline your workflow. I have two computers I develop on, a Macbook and a Mac Pro desktop. Switching between them is often frustrating because my dotfile customizations I use on one are not found on the other until I set them up. I knew there had to be a better way to keep my ever-changing dotfiles synced.

I have a MobileMe account with Apple and already use it to synchronize my life between my two Macs and my iPhone. It rocks and is well worth the subscription for the convenience it affords. This past week I started thinking about whether it would be possible to sync other files between my Macs. I decided to start with my dotfiles as a simple and easy proof of concept. Here’s how I did it:

The computers you’ll be syncing must use the same MobileMe account since you’ll be using the iDisk as the vehicle of synchronization. The first thing you want to do is enabled iDisk sync on the computers.  iDisk sync can be enabled in MobleMe settings in System Preferences. Choose the iDisk option and set iDisk Sync to On and choose Automatically as the update choice.  This will enable your iDisk files to be synced and downloaded to your computer regularly so you can access them offline. Otherwise, all your iDisk files are stored in the cloud and you wouldn’t have access to your dotfiles if you were offline.

iDisk sync should be on and set to automatic.

Open your iDisk on one of the computers and create a permanent location for your dotfiles. For this tutorial I’ll be using what I have set up which is have a folder called Misc and inside there I have a folder called Dotfiles. You can set it up however you like, as long it it’s permanent. If you move or rename this location you will need to redo the symlinks.

Next choose which computer’s dotfiles will be the ones you want to use and move them to your chosen folder on your iDisk. By default, dotfiles are invisible in the Finder, so you’ll need to use the Terminal. The iDisk should be found under /Volumes/iDisk:

mv .profile /Volumes/iDisk/Misc/Dotfiles/.
mv .bashrc /Volumes/iDisk/Misc/Dotfiles/.
mv .bash_profile /Volumes/iDisk/Misc/Dotfiles/.
mv .bash_login /Volumes/iDisk/Misc/Dotfiles/.
mv .gitconfig /Volumes/iDisk/Misc/Dotfiles/.
mv .gitk /Volumes/iDisk/Misc/Dotfiles/.
mv .gitignore /Volumes/iDisk/Misc/Dotfiles/.
mv .irbc /Volumes/iDisk/Misc/Dotfiles/.
mv .rails-plugin-sources /Volumes/iDisk/Misc/Dotfiles/.

These are just some of the dotfiles I like to keep synced (my list goes on and also includes some non-dotfiles in my root directory). Yours will no doubt be different depending upon which shells and tools you use. The world is your oyster here, so don’t hold back.

Now that your dotfiles have been moved over it’s time to link to them using a symbolic link. A symbolic link is basically an alias or pointer to an actual file located somewhere else:

ln -s /Volumes/iDisk/Misc/Dotfiles/.profile .
ln -s /Volumes/iDisk/Misc/Dotfiles/.bashrc .
ln -s /Volumes/iDisk/Misc/Dotfiles/.bash_profile .
ln -s /Volumes/iDisk/Misc/Dotfiles/.bash_login .
ln -s /Volumes/iDisk/Misc/Dotfiles/.gitconfig .
ln -s /Volumes/iDisk/Misc/Dotfiles/.gitk .
ln -s /Volumes/iDisk/Misc/Dotfiles/.gitignore .
ln -s /Volumes/iDisk/Misc/Dotfiles/.irbc .
ln -s /Volumes/iDisk/Misc/Dotfiles/.rails-plugin-sources .

When you do an ‘ls -al’ in Terminal you should see your newly created dotfile symlinks. Log out of Terminal and log back in and check to see if your environment is working. Test your aliases, etc. If you set everything up correctly, things should work as they always have. If not, check your work.

Now that the first computer is set up and dotfiles are on your iDisk you can go ahead and set up any other computers you want to synchronize. This time you will just be deleting the dotfiles from the computer:

rm -f .profile .bashrc .bash_profile .bash_login .gitconfig .gitk .gitignore .irbc .rails-plugin-sources

Once they are deleted your can repeat the symlink step you did on the first computer. One thing to watch for: make sure your iDisk on both computers have synced. They will sync automatically every 10 minutes or so, but if you’re real quick, the dotfiles might not show up yet on the other computers. Either go get a cup of coffee or try doing a manual sync on all your computers, starting with the first one you set up. Once they are synced, do your symlinks and test to make sure everything works.

That’s it. You’re done! Now, if you make a dotfile change on any of the computers, it will be automatically synced to the others. It’s a very simple thing, but a huge convenience.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments