Some people keep their dotfiles in a repo and distribute them across all machines they work on. However, quite often a specific machine needs some specific setup in terms of aliases, environment variables, etc. These changes are machine-specific and should not pollute the general dotfiles (repo). I achieve this by what a call “local” dotfiles. Here is my setup:

I have my dotfiles in the repo ~/src/dotfiles. Depending on the environment, I link to the dotfiles I need:

$ cd ~
$ ln -s ~/src/dotfiles/.alias
$ ln -s ~/src/dotfiles/.envvars
# ...

Now, my .zshrc (like .bashrc, just using the excellent zsh shell) contains the following:

DOTFILES=(~/.alias* ~/.envvars* ~/.functions*)
for f in $DOTFILES; do source $f; done

This will obviosly source the different dotfiles in my home dir. The little * allows to further load the “local” dotfiles.

As an example, the stock ~/.envars may look like this:

export PAGER='less -s -M'
export EDITOR='vim'
export PATH="${HOME}/bin:${PATH}"

And the ~/.envars.local appends some more info:

export PATH="${PATH}:/path/to/some/server/dependent/location"

I am using a similar concept in my .vimrc. At the end of it, I have the line source $HOME/.vimrc.local. When setting up a new environment, I’ll run:

$ cd ~
$ ln -s ~/src/dotfiles/.vimrc
$ touch .vimrc.local

The local files also allow to try out new settings which will may eventually be merged into the repo containing the stock dotfiles. You should not forget to merge them eventually, though!

Related Posts