Live data from Hacker News

Using GNU Stow to manage your dotfiles

brandon.invergo.net

31–40 of 69 posts

Re: Using GNU Stow to manage your dotfiles

#32
A while back I got very interested in cleaning up my configuration files. I wanted to figure out out a way to store all of the configurations I use across multiple machines into a single repository, while at the same time not having to worry about symlinking and installing configurations for things I don't need on a particular machine.

I looked at a lot of different things like Stow and homeshick and the like and really didn't like any of the solutions. So I ended up writing my own tool.

I've wanted to write up something for it for awhile now and post it around, but I just haven't yet. Anyway, here's my tool: https://github.com/EvanPurkhiser/dots

Re: Using GNU Stow to manage your dotfiles

#33

I just have a dotfiles repo on github that I clone to any new computer I'm using. Then make a symbolic link between the dotfiles and the repo (`ln -s ~/dotfiles/.whatever ~/.whatever`). Super simple.

This is almost exactly the same strategy, only stow handles the symlinks for you, so you don't have to go through and `ln -s` all your files/directories. Your dotfiles still go in a git repo.

I put the "ln -s" commands in a shell script.

    git clone ... ~/.my-config
    ~/.my-config/setup-links
Done.

Some servers at work don't have Git installed (and certainly not Stow), so I rsync ~/.my-config from my workstation to my home directory. (There's little need for me to edit my .zshrc on a server.)

Re: Using GNU Stow to manage your dotfiles

#34
post #10

Earlier quoted context omitted.

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 | rsyn…

I have very similar setup to yours, but my solution is to use a bare repository. To set up dotfiles on a new computer is just

    $ git clone --bare git@github.com:mbudde/homedir.git .homegit
    $ git --git-dir=.homegit --work-tree=~ checkout -f    # Overwrite existing files
    $ echo '*' >> .homegit/info/exclude
And then I have a simple git wrapper script [1]. I moved from using an alias to a script for some reason I can't remember (and of cause I didn't write it in the commit message -_-).

[1] https://github.com/mbudde/homedir/blob/master/usr/bin/hgit

Re: Using GNU Stow to manage your dotfiles

#35
post #22

Earlier quoted context omitted.

I just made ~/.git and ignore everything with .gitignore, whitelisting files I want to commit: https://github.com/burke/dotfiles/blob/master/.gitignore It works really well for me.

I remember giving advice once, to someone who did that and then git clean -dfx

That is terrifying. I just added this to my zshrc:

    git() {
      local toplevel=$(command git rev-parse --show-toplevel 2>/dev/null)
      if [[ "${toplevel}" == "${HOME}" ]] && [[ "$1" == "clean" ]]; then
        >&2 echo "Do NOT run git clean in this repository."
        return
      fi
      command git "$@"
    }

Re: Using GNU Stow to manage your dotfiles

#36
I created something a while ago (that I haven't updated in a while, I shamefully admit) that also handles dot files:

http://configr.io

I also do namespaced dotfile saving (folder by application), but I focused on WGET/CURL-ability (which is unfortunately hard to divine from the current website UI -- the curl command is not obvious, as you have to have content-disposition turned on.

Re: Using GNU Stow to manage your dotfiles

#38
I don't know whether it was just unclear to me or unclear in this article but (after checking man stow), here is the relevant section of the man page that cleared up how it worked for me:

The stow directory is assumed to be the value of the "STOW_DIR" environment variable or if unset the current directory, and the target directory is assumed to be the parent of the current directory (so it is typical to execute stow from the directory /usr/local/stow). Each package given on the command line is the name of a package in the stow directory (e.g., perl). By default, they are installed into the target directory (but they can be deleted instead using "-D").

Re: Using GNU Stow to manage your dotfiles

#39
What I do is just keep all of the dotfiles in ~/dotfiles and symlink them to the home directory, then I can keep track of them with git. Doesn't have to be any more work than that. Maybe it's not an issue for me because I only use one machine, and when I switch to another, I just pull down my dotfiles from github and symlink them again. I only do this every couple years.

Re: Using GNU Stow to manage your dotfiles

#40
The article doesn't explain how stow 'knows' where to place the symlinks.

The answer is (of course) in the help output:

  -d DIR, --dir=DIR       Set stow dir to DIR (default is current dir)
  -t DIR, --target=DIR    Set target to DIR (default is parent of stow dir)
Post reply on HN