Live data from Hacker News

Using GNU Stow to manage your dotfiles

brandon.invergo.net

11–20 of 69 posts

Re: Using GNU Stow to manage your dotfiles

#11
This is how I manage my dotfiles since I discovered stow a couple of months ago.

The only thing that bugs me is that I haven't figured out an elegant way to have some configs include machine specific configs. For example a set of bash aliases that I only use at work but don't want at home.

My best idea is to source all files in, say ~/.bashrc.d and put machine specific configs in there... Haven't tried it out yet.

Re: Using GNU Stow to manage your dotfiles

#12
post #9

This makes no sense. Somehow having a versioned dotfiles directory with either a Makefile or a shell script is "hard" because either you need to have Python (no you don't, shell script is fine) or you forget the name of the install script (type ls), but somehow using this software (which needs to be installed) is "easier". With this software you also need to remember the magic invocation, a trivial thing in both scen…

This use case is one of the expressed reasons for stow's existence.

"GNU Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place. This is particularly useful [to] facilitate a more controlled approach to management of configuration files in the user's home directory, especially when coupled with version control systems." [1]

Installing a single binary might be easier than installing a scripting environment on a server that may have existing versioning considerations. (brew install stow | sudo apt-get install stow)

You literally type `stow bash` and you're done.

----

[1]: http://www.gnu.org/software/stow/

Re: Using GNU Stow to manage your dotfiles

#14
I gave GNU Stow a try, but thought it did too much.

Ended up using dotfiles (https://pypi.python.org/pypi/dotfiles). My dotfiles (https://github.com/cjoelrun/dotfiles). I handle system specific stuff in each config: OS checks in zsh, emacs, tmux configs. Allows me to move between OSX and Arch linux.

Re: Using GNU Stow to manage your dotfiles

#15
post #11

This is how I manage my dotfiles since I discovered stow a couple of months ago. The only thing that bugs me is that I haven't figured out an elegant way to have some configs include machine specific configs. For example a set of bash aliases that I only use at work but don't want at home. My best idea is to source all files in, say ~/.bashrc.d and put machine specific configs in there... Haven't tried it out yet.

Not sure if this would work with Stow, but in my .bashrc I just do this:

  if [ -f ~/config/bashrc_$(hostname -s) ]; then
        source ~/config/bashrc_$(hostname -s)
  fi
this gives me machine specific configs.

Re: Using GNU Stow to manage your dotfiles

#16
I prefer dedicated repositories (I use mercurial) for each app (vim, mutt, etc.) or context (X11) that include Makefiles for creating the necessary links or handling some environment-specific details. This still allows me to cherry pick what I want on each machine, but keeps the commit history in the appropriate repo.

Re: Using GNU Stow to manage your dotfiles

#17
post #11

This is how I manage my dotfiles since I discovered stow a couple of months ago. The only thing that bugs me is that I haven't figured out an elegant way to have some configs include machine specific configs. For example a set of bash aliases that I only use at work but don't want at home. My best idea is to source all files in, say ~/.bashrc.d and put machine specific configs in there... Haven't tried it out yet.

I also use stow to manage my common personal dotfiles, as well as my employer-specific dtofiles. The way I do this is to keep my general files in my dotfiles repository, but then keep work specific ones in a separate repo (dotfiles-employer).

This separate repo has .private versions of all of my commonly used dotfiles (for example .bashrc.private), and my top-level files will check for the existence and source these, if present.

Both repos will be installed using stow, with the work dotfiles generally just extending the personal dotfiles.

Re: Using GNU Stow to manage your dotfiles

#18
post #10

> but many/most dotfiles reside at the top-level of your home directory, where it wouldn't be a good idea to initialize a VCS repository. Right. Which is why I use git with a workspace detached from the git directory. The git directory is in ~/dotfiles/.git, with "git config core.worktree ~", and I set an alias "dgit=git --git-dir ~/dotfiles/.git". The advantage of this method is that there are no symlinks to maintai…

This is great! It fixes the only problem I have with maintaining my dotfiles as a git repo: the .git dir in ~. That interferes with so many things such as the CtrlP vim plugin, the integration of git with the bash prompt and many other things. Thank you for this.

Yeah, the git in the bash prompt thing was the most annoying thing to me, honestly :)

Since there is interest, I'll elaborate on the understated "a bit painful" part of moving the files after an initial clone which leaves the files in the ~/dotfiles dir. The problem is that I didn't find an easy "move and overwrite recursively" command in Linux.

Here's the magic command from my script: git ls-files --cached -z | rsync -av --from0 --remove-source-files --files-from - ${dir} ~/ && find . -type d -empty -delete

To spell it out, it's having git list all the files in the repo (so skipping any unversioned files such as the .git dir itself), using the NUL byte as file termination to avoid any (most?) special character issues in file names, and using rsync to move the files over thanks to --remove-source-files. However rsync doesn't remove empty directories (durr), so have the find do that.

Also, you probably want to set "git config status.showUntrackedFiles no" ;)

Re: Using GNU Stow to manage your dotfiles

#19
post #11

This is how I manage my dotfiles since I discovered stow a couple of months ago. The only thing that bugs me is that I haven't figured out an elegant way to have some configs include machine specific configs. For example a set of bash aliases that I only use at work but don't want at home. My best idea is to source all files in, say ~/.bashrc.d and put machine specific configs in there... Haven't tried it out yet.

Not sure if this would work with Stow, but in my .bashrc I just do this: if [ -f ~/config/bashrc_$(hostname -s) ]; then source ~/config/bashrc_$(hostname -s) fi this gives me machine specific configs.

You can do something similar to target *nix platforms like Darwin|FreeBSD|Linux|NetBSD|OpenBSD with:

  if [ -f ~/config/bashrc_$(uname -s) ]; then
      source ~/config/bashrc_$(uname -s)
  fi

Re: Using GNU Stow to manage your dotfiles

#20
post #11

This is how I manage my dotfiles since I discovered stow a couple of months ago. The only thing that bugs me is that I haven't figured out an elegant way to have some configs include machine specific configs. For example a set of bash aliases that I only use at work but don't want at home. My best idea is to source all files in, say ~/.bashrc.d and put machine specific configs in there... Haven't tried it out yet.

Not sure if this would work with Stow, but in my .bashrc I just do this: if [ -f ~/config/bashrc_$(hostname -s) ]; then source ~/config/bashrc_$(hostname -s) fi this gives me machine specific configs.

Great idea! It wouldn't work for me though as I tend to call all my machines 'fuckup' (I know...) ;)
Post reply on HN