electronic brain surgery since 2001

Managing dotfiles with DropBox

I'm using DropBox1) to keep personal config files in sync through multiple computers. To do so I need to place the actual files inside the dropbox folder and then symlink them from my homedir.

My setup looks like this:

.gitconfig -> Dropbox/dotfiles/gitconfig
.gnupg -> Dropbox/dotfiles/gnupg
.ssh -> Dropbox/dotfiles/ssh
.vimrc -> Dropbox/dotfiles/vimrc

But these symlinks need to be created on every computer I sync to. And they need to be updated on every computer when a new file or directory is added.

To make this easier, I came up with the following little shell script:

cd `dirname $0`
F=`pwd |sed -e "s#$HOME/\?##"`
for P in *
    # skip setup
    if [ "$P" = "setup.sh" ]; then continue; fi
    # ensure permissions
    chmod -R o-rwx,g-rwx $P
    # skip existing links
    if [ -h "$HOME/.$P" ]; then continue; fi
    # move existing dir out of the way
    if [ -e "$HOME/.$P" ]; then
        if [ -e "$HOME/__$P" ]; then
            echo "want to override $HOME/.$P but backup exists"
        echo -n "Backup "
        mv -v "$HOME/.$P" "$HOME/__$P"
    # create link
    echo -n "Link "
    ln -v -s "$F/$P" "$HOME/.$P"

Now all I have to do is running Dropbox/dotfiles/setup.sh to update all the symlinks. Should a file or directory already exist, the script renames it before replacing it with the correct symlink.

dropbox, linux, homedir, dotfiles
Similar posts:
sign up through this link to get 250MB more space