Keeping track of configuration files

Chances are, you won't spend the next ten years using the same computer. It's also possible you have multiple machines you work acrossso you should probably find a way to synchronize your configuration files across multiple environments.

As usual, there's no single right way to do this, but a common practice is to store files in a Git repository (often called dotfiles, since configuration files in Linux tend to start with a dot), and pointing symlinks from the files in the home directory to the files in the dotfiles directory. All you'll have to do is commit, push, and pull the configuration with Git on each machine to stay up to date.

The easiest way would probably be to create a repository using a service such as GitHub, and utilize it to synchronize your configuration. Just don't store any sensitive information like passwords in version control!

Most frequently, the process of changing my configuration files is as follows (I store mine in $HOME/.dotfiles on Linux and Mac, and %USERPROFILE%\_dotfiles on Windows):

$ cd ~/.dotfiles
$ git pull --rebase
# Make the desired changes, like editing .vimrc
$ git commit -am "Updated something important"
$ git push
 The .dotfiles should be a git repository, see Quick and dirty in Chapter 5Build, Test, and Execute to learn how to create one and if you'd like a refresher on Git.

For example, you might have a repository in ~/dotfiles, which contains .vimrc and .gvimrc files, as well as a .vim directory. You could create links manually (ln -s ~/dotfiles/.vimrc .vimrc), or by writing a small Python script like this:

import os

dotfiles_dir = os.path.join(os.environ['HOME'], 'dotfiles')
for filename in os.listdir(dotfiles_dir):
os.symlink(
os.path.join(dotfiles_dir, filename),
os.path.join(os.environ['HOME'], filename))

 

You can get infinitely creative with solutions to this problem. Here are just a few examples of where you can take this:

  • Make the preceding Python script work cross-platform (for instance, .vim directory becomes vimfiles in Windows)
  • Periodically synchronize the Git repository using a cron job
  • Use some form of file sync instead of Git (trading informative commit messages for near-instant update across machines)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.216.18