Computer Science
Algorithm
Data Processing
Digital Life
Distributed System
Distributed System Infrastructure
Machine Learning
Operating System
Android
Linux
Backup My Dotfiles (2012)
MacOS
Tizen
Windows
iOS
Programming Language
C++
Erlang
Go
Scala
Scheme
Type System
Software Engineering
Storage
UI
Flutter
Javascript
Virtualization
Life
Life in Guangzhou (2013)
Recent Works (2013)
东京之旅 (2014)
My 2017 Year in Review (2018)
My 2020 in Review (2021)
十三年前被隔离的经历 (2022)
A Travel to Montreal (2022)
My 2022 in Review (2023)
Travel Back to China (2024)
Projects
Bard
Blog
RSS Brain
Scala2grpc
Comment Everywhere (2013)
Fetch Popular Erlang Modules by Coffee Script (2013)
Psychology
耶鲁大学心理学导论 (2012)
Thoughts
Chinese
English

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:

check_link() {
	LINK=`pwd`/$1
	TARGET=~/$2
	if [ -h $TARGET ] ; then
		echo -n "remove symbolic link: "
		rm -v $TARGET
	elif [ -e $TARGET ] ; then
		echo -n "move: "
		mv -v $TARGET $TARGET.old
	fi
	echo -n "link: "
	ln -sv $LINK $TARGET
}

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