Wow, what a title for a blog entry… I hope the entry itself can live up to the generated expectations So, what I want to talk about is how to use the same configuration files for programs I use everyday – such as bash, vim or ssh, just to name a few – in different places:
- My PC at home
- My laptop
- My girlfriend’s PC (also running Arch, of course) on which I regularly need to do administrative work
- The Arch live system on a USB stick
- My PC at work
Now, in each of these work places, I regularly modify configurations or even add new ones. What has always bugged me is that I have a hard time synchronizing these changes. So I thought: How about employing a revisioning system to do the work for me?
Which system to use?
At first, I wanted to use subversion, as I already got used to it during my diploma thesis and got even more experience from using it everyday at work. But then I remembered that I had read about git and how great it was supposed to be and indeed, it has some advantages over subversion for my plans.
The most important one is that it is a distributed system, meaning that I could pull from any workspace, instead of just a central repository. This could come quite handy if I only got my laptop with me or my PC at home isn’t running, but the one of my girlfriend is. Not to mention how helpful this is when my desktop PC should crash!
Now that I decided which tool to use, I needed to decide how to layout the directory structure. My first idea was to simply create a repository inside my
$HOME under which I could add all my config files. But that would have forced me to always check out the configuration files of all tools I’m using at the specific computer I’m at instead of only the ones I need.
So I created a subdirectory under my
$HOME and added another subdirectory for each tool whose settings I’d like to keep track of. That’s when I noticed that many tools already use the
$HOME/.config directory for exactly this purpose and so I did as well. The layout now looks like this:
$HOME + .config + vim + bash + ssh + ...
To have the respective tool find the config file, I just add a softlink (remember to remove/backup the original files first):
ln -s $HOME/.config/bash/.bashrc $HOME/.bashrc ln -s $HOME/.config/vim/.vimrc $HOME/.vimrc ln -s $HOME/.config/vim/.vim $HOME/.vim # and so on, I think you get the idea...
I don’t want to give a full tutorial to git here, but the following should be enough to help you getting started. As an example, let’s set up a repository for bash based on an existing
mkdir -p $HOME/.config/bash cd $HOME/.config/bash git init cp $HOME/.bashrc . git add .bashrc git commit -m 'Initial commit'
That’s it! You successfully initialized your first repository. To check it out from another PC, I use ssh, for which a server obviously needs to be running on the machine which we want to check out from:
cd $HOME/.config git clone ssh://User@Server:Port/~/.config/bash bash
Replace User, Server and Port with your username on the server, the server’s url or ip address and the port on which the ssh server is listening, respectively. If your username on the server is the same as on the client, you can skip it, just as you can skip the port specification if the server is listening on port 22. To make your life easier, you can preconfigure these settings in the
$HOME/.ssh/config file. See
man ssh_config for details on how to do this.
This concludes the first part of this tutorial. I definetely plan to give some examples about how to fetch and push changes with git. See you then, if you’re interested.