Hacker News new | ask | show | jobs
by zorbo 4252 days ago
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.

1 comments

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" ;)

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

This definitely looks like a better alternative!
> I didn't find an easy "move and overwrite recursively" command in Linux.

You don't need recursiveness into commands, just use find (maybe with xargs) to generate the list of files to overwrite (or commands to execute).

That's what I did in my first iteration, except find is hell.

No wait, I mean find is a really powerful and sophisticated tool, but it takes time and effort to get it to do precisely what you want. It turned out rsync did what I wanted more easily.

Find has an atrocious syntax. Nowadays, I seldom use any other feature of find rather than just enumerating files. Rather, I enumerate files, create commands on them (with things like xargs and sed), and pipe the output into sh. Generating code is a very flexible technique, and it's actually easier (and safer) that trying to muck with find options.