Terminal: synchronize config with git
2013-01-04
We have access to more than one computer and every bash/zsh/vim/… needs a configuration. I’ve tried several things to keep it in sync (rsync, unison, …), but at the end I used git.
create:
cd ~ mkdir .config cd .config git init
vi ~/.config/1_create_links.sh
#!/bin/bash now=`date "+%Y%m%d-%H%M%S"` if [ -e ~/.alias -a ! -L ~/.alias ]; then mv ~/.alias ~/.alias-$now; fi if [ -e ~/.bashrc -a ! -L ~/.bashrc ]; then mv ~/.bashrc ~/.bashrc-$now; fi if [ -e ~/.dir_colors -a ! -L ~/.dir_colors ]; then mv ~/.dir_colors ~/.dir_colors-$now; fi if [ -e ~/.inputrc -a ! -L ~/.inputrc ]; then mv ~/.inputrc ~/.inputrc-$now; fi if [ -e ~/.vim -a ! -L ~/.vim ]; then mv ~/.vim ~/.vim-$now; fi if [ -e ~/.vimrc -a ! -L ~/.vimrc ]; then mv ~/.vimrc ~/.vimrc-$now; fi if [ -e ~/.Xdefaults -a ! -L ~/.Xdefaults ]; then mv ~/.Xdefaults ~/.Xdefaults-$now; fi if [ -e ~/.zshrc -a ! -L ~/.zshrc ]; then mv ~/.zshrc ~/.zshrc-$now; fi if [ -e ~/.ssh/config -a ! -L ~/.ssh/config ]; then mv ~/.ssh/config ~/.ssh/config-$now; fi ln -s ~/.config/alias ~/.alias ln -s ~/.config/bashrc ~/.bashrc ln -s ~/.config/dir_colors ~/.dir_colors ln -s ~/.config/inputrc ~/.inputrc ln -s ~/.config/vim ~/.vim ln -s ~/.config/vimrc ~/.vimrc ln -s ~/.config/Xdefaults ~/.Xdefaults ln -s ~/.config/zshrc ~/.zshrc ln -s ~/.config/ssh/config ~/.ssh/config
Now you can create the config files.
When you are finished you can go one with commiting the changes, creating a new git repository on the server and push it
cd ~/.config git add * git commit ssh server mkdir ~/git cd ~/git git --bare init config exit git remote add origin ssh://servername.example/~/git/config git push
on a new client you can simply clone the repository from the server and run the script to create the links
git clone ssh://servername.example/~/git/config ~/.config ~/.config/1_create_links.sh
You want to change a file and sync it? On the host where you have done the change:
cd ~/.config git add * git commit git push
On the other hosts:
cd ~/.config git pull