Backup My Dotfiles

Posted on 05 Dec 2012, tagged vimzshconfiggit

These days I re-configure my vim and zsh. Then backup them in github. You can see it at here.

Using github to backup dotfiles is really a comfortable way. In this way, you can:

  • Feel free to change your configures, since if you don’t like the configure some day, you can roll it back.
  • Update your configures anywhere. Just use git to clone your configure files from github.
  • Keep different versions for different machines (Such as for desktop and laptop). Just use branch to control them.
  • If you are using vim plugins from git repo or something like oh-my-zsh, you could simple use git submodule to keep track of them.

The basic idea is put configure files in a directory such as dotfile and use git to track it. Then make a symbolic link to home. However, manual make symbolic links is boring. Firstly I am thinking of use the same directory structure as ~/ and then automatic link them. But there comes some problems: for some directories such as .vim, we should make a link for them while for some directories such as .config, we may only want to link openbox under it to ~/.config/openbox. It seems impossible to use an automatic way totally. But some shell code could make life a little easy:

 1check_link() {
 2        LINK=`pwd`/$1
 3        TARGET=~/$2
 4        if [ -h $TARGET ] ; then
 5                echo -n "remove symbolic link: "
 6                rm -v $TARGET
 7        elif [ -e $TARGET ] ; then
 8                echo -n "move: "
 9                mv -v $TARGET $TARGET.old
10        fi
11        echo -n "link: "
12        ln -sv $LINK $TARGET
13}

Usage: check_link <path_in_dotfiles> <path_in_home>, such as check_link vim/vimrc .vimrc. See my github repo for details.

comments powered by Disqus