Hacker News new | ask | show | jobs
by AdamGibbins 5164 days ago
While we're on the subject - has anyone found a good way to separate environments while keeping your setup fairly DRY? e.g. I have slight variations in my aliases for work/home, different git config email etc.

You can find mine here: http://github.com/adamgibbins/dotfiles

8 comments

Towards that end, (and for keeping certain sensitive things from repos...) I made this:

https://github.com/sophacles/dotfuse

It is a fuse filesystem that allows for modularization of some "single file" style dotfiles. Combined with git branche or modules (or both) it can get a lot of this (i hope). Warning though, it is still a bit of a toy, and I haven't played with it for a while, but I'm open to suggestions and pull requests!

As for dry with sourceable stuff, like bash/zsh configs, you can just keep the environment specific stuff in a separate repo, and use git modules, that is if your environ specific stuff needs to be confidential (or some of it) and kept in separate private repos.

this is clever, thanks for sharing
I see you have a zshrc.local; that's the same approach I use. Unfortunately not everything supports "includes" but many, many things do.

If you want to see more, https://github.com/apinstein/dotfiles

I suppose another alternative might be having a private ".local" repo as a submodule, and having a rake task to concatenate and install the shared & local files. It is a tricky problem.

My zshrc.local setup is rather poor and I need to find time to sort it out correctly - currently its effectively a clone of the standard grml setup (http://grml.org/zsh/).
I haven't done this yet, but I'm guessing you could just branch off of master, and create a "home" or "work" branch.

To me that might be better than using setup scripts for the various environments, and keeping it all in one branch (like I've seen other people do).

I'd prefer to see the differences by doing things like:

    git diff master work
or

    git diff home work
etc
You should take a look at http://vcs-home.branchable.com/ They have a mailing list and a bunch of resources to do similar things.

Right now I use movein[1] to maintain my dot files. Each dotfile is held in it's own repo which is checked out to $HOME via GIT_DIR and GIT_WORK_TREE environment variables. The mr[2] command ties the git repos together as it if was one repo. I use additional repos or branches to handle variations within dotfiles. For work, I try to keep things confined to the relevent directory eg. using local.vimrc[3]

[1] http://stew.vireo.org/movein [2] http://kitenet.net/~joey/code/mr/ [3] https://github.com/embear/vim-localvimrc

Here's my solution: https://bitbucket.org/davidn/dotstuff

Briefly: ~/dotstuff is a hg/git/whatever repo that contains your dotfiles, which can optionally use simple preprocessor directives to turn on or off different sections on different systems, or contain macro substitutions. You run 'dot' and it shows you a diff between what's in the repo and what's in your filesystem. Then run 'dot -g' to make the changes (with optional backups). Also manages crontabs.

I wrote it about four years ago and have been using it happily since then to manage dotfiles on 2-4 different systems. (I wrote the README today before posting this, which is why it has today's date.)

I have a "~/.hostclass" file on all systems, created manually, which contains some string identifying which confiv variant to use on that machine. EG, "home", "work".

Then, my config files are "make"'d by concatting three files: cat "$1.first" "$1.`cat ~/.hostclass`" "$1.end" > ~/.$1

This lets me split out specific parts into a hostclass-specific file.

Generally, I set variables in these files that gets used in the $1.end file.

It works pretty well for me, since my hosts are generally pretty close to each other.

I haven't done it yet, but I've been meaning to set up a very simple solution to this using a preprocessor (probably m4). I think wrapping a few blocks in if-statements based on the host name will go pretty far.

edit: might as well link my repo, which doesn't yet include that functionality: https://github.com/drewfrank/dotfiles

I've got a preprocessor (ruby) in my zsh dotfiles:

https://github.com/halostatue/dotfiles

I've been slowly moving toward a 'detect-and-configure' plug-in system that I'm quite happy with.

I found vcsh to be very effective. Files live directly in $HOME but the .git repository is in a special directory.

https://github.com/RichiH/vcsh