publishing your dotfiles

linux, sage

I discovered freehg.org today, which is a free mercurial repo hosting site. In spirit it’s very akin to github, but obviously lacks many of the features and much of the polish. However, this particular purpose, it’s more than sufficient.

If you access many *nix machines on a regular basis, you’ve probably have been annoyed that your custom configuration files are not immediately available. I used to scp config files around all the time, but that gold old quick. I’m going to show you my current setup for making sure that all the dotfiles (zshrc, vimrc, etc) that I use are version controlled and are easily accessible.

First, collect all your dotfiles in one directory and make it an hg repository. I use ~/.dotfiles, you can use whatever you like.  Here is what my .dotfiles looks like:

iapetus:~/.dotfiles> ls -l
total 54k
-rw-r--r-- 1 yqiang staff   85 2008-07-04 10:20 ackrc
-rw-r--r-- 1 yqiang staff   50 2008-05-29 18:24 bash_profile
-rw-r--r-- 1 yqiang staff 2.0k 2008-05-29 18:24 bashrc
-rw-r--r-- 1 yqiang staff  569 2008-07-04 14:09 create_symlinks.py
drwx------ 3 yqiang staff  102 2008-06-13 15:52 gtk-2.0
-rw-r--r-- 1 yqiang staff  624 2008-07-04 09:48 gvimrc
-rw-r--r-- 1 yqiang staff   48 2008-06-17 15:46 hgignore
-rw-r--r-- 1 yqiang staff  454 2008-07-04 10:30 hgrc
drwx------ 5 yqiang staff  170 2008-06-29 17:55 irssi
-rw-r--r-- 1 yqiang staff  403 2008-06-22 11:20 pdbrc
-rw-r--r-- 1 yqiang staff  642 2008-06-29 10:49 screenrc
-rw-r--r-- 1 yqiang staff 6.8k 2008-07-04 13:39 vimrc
-rw-r--r-- 1 yqiang staff 5.8k 2008-06-29 17:43 zshrc

Then create a freehg.org account and initialize a public repo there. You can find mine at:

http://freehg.org/u/yqiang/dotfiles/

Now, when you access a new machine, to get all your dotfiles in order, just do:

veritas:~ > hg clone http://freehg.org/u/yqiang/dotfiles/ .dotfiles
requesting all changes
adding changesets
adding manifests
adding file changes
added 22 changesets with 37 changes to 15 files
15 files updated, 0 files merged, 0 files removed, 0 files unresolved
veritas:~ > cd .dotfiles
veritas:~/.dotfiles > python create_symlinks.py
Symlinking /home/yqiang/.dotfiles/zshrc to /home/yqiang/.zshrc
Symlinking /home/yqiang/.dotfiles/gvimrc to /home/yqiang/.gvimrc
Symlinking /home/yqiang/.dotfiles/bash_profile to /home/yqiang/.bash_profile
Symlinking /home/yqiang/.dotfiles/hgignore to /home/yqiang/.hgignore
Symlinking /home/yqiang/.dotfiles/bashrc to /home/yqiang/.bashrc
Symlinking /home/yqiang/.dotfiles/hgrc to /home/yqiang/.hgrc
Symlinking /home/yqiang/.dotfiles/pdbrc to /home/yqiang/.pdbrc
Symlinking /home/yqiang/.dotfiles/ackrc to /home/yqiang/.ackrc
Symlinking /home/yqiang/.dotfiles/screenrc to /home/yqiang/.screenrc
Symlinking /home/yqiang/.dotfiles/vimrc to /home/yqiang/.vimrc

create_symlink.py is a simple python script that will create the symlinks for you. Here is the code for it:

#!/usr/bin/env python
import os
home = os.path.abspath(os.environ['HOME'])
path = os.path.join(home, '.dotfiles') 
excludes = ['gtk-2.0', 'create_symlinks.py']
for f in os.listdir(path):
    if f.startswith('.'):
        continue
    if f not in excludes:
        dst = os.path.join(home, '.' + f)
        src = os.path.abspath(f)
        try:
            print "Symlinking %s to %s" % (src, dst)
            os.symlink(src, dst)
        except Exception, msg:
            print "Failed to symlink %s to %s " % (src, dst)
            print msg

Tada. All your config files are in place now. If you’re really into it, you can run a cron script that automatically does an hg pull so you don’t even have to think about it.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Mixx
  • Google

16 Responses to “publishing your dotfiles”

  1. Andrew Says:
    July 4th, 2008 at 3:59 pm

    Of course, you should be aware that many of those files could easily be used to compromise your system if modified by a third party, and so automatically receiving them over an insecure network without any form of cryptographic integrity checking (which you won’t get with the recipe in the post) is a bit like asking for your computer to be compromised.

  2. admin Says:
    July 4th, 2008 at 4:09 pm

    Hey Andrew,
    That’s a great point. I suspect though that there are quite a few things I do everyday which is being transferred as clear text that could compromise security in one way or another. Maybe freehg.org will provide https. I’ll definitely ask the guy who runs it.

  3. X Y Says:
    July 4th, 2008 at 5:22 pm

    Sign the changesets, and only accept signed changesets.
    http://www.selenic.com/mercurial/wiki/index.cgi/GpgExtension

  4. Yi Qiang Says:
    July 4th, 2008 at 6:07 pm

    Cool. I actually had the extension enabled and totally forgot about it. Good suggestion!

  5. Mark Says:
    July 4th, 2008 at 7:01 pm

    This is a nice idea, but I think the make symlinks script could be done much more succinctly in bash shell rather than python. I have something similar, and my make symlinks script looks like this:

    $DIR=~/hg/dotfiles/home_dir
    cd $DIR
    for i in *; do ln -s $DIR/$i ~/.$i; done

    If you need the excludes functionality, then you can turn on the extglob option in bash and use a pattern like !(make_symlinks.sh) instead of *.

  6. itsadok Says:
    July 4th, 2008 at 11:38 pm

    I believe that:
    ln -s ~/hg/dot_files/* ~/
    should do the trick.
    You might want to do -sf, to override whichever dot files are already in there.

  7. SJS Says:
    July 4th, 2008 at 11:46 pm

    Mercurial supports ssh, which handles the network security aspect. Storing your configuration data on someone else’s server is kind of dumb — you’re needlessly trusting someone, thus leaving yourself vulnerable to their system becoming compromised also compromising your system.

    If you have sufficient *nix accounts to make this sort trick useful, then you can probably host your definitive repository on your most stable (and trusted) machine. If you insist on centralizing your dotfiles, you might as well as use CVS.

    Finally, creating a large suite of platform-independent initialization scripts can get a bit tricky, especially if you’re not working on a homogenous network of machines. One of the more useful things to do with initialization files is to handle differences between machines — on alpha.yourdomain.tld you may use /usr/local for locally installed files, while on beta.mydomain.tld I use /opt, and your ISP’s gamma.isp.tld uses /sfw… take special care when writing your dotfiles.

  8. BVK Chaitanya Says:
    July 5th, 2008 at 3:07 am

    Interesting…I use exactly the same way and same site. Mine could be found at http://freehg.org/u/bvk/config

    I don’t have any script to create the symlinks yet, but i have plans to do it from sometime.

    ;-)

  9. Yi Qiang Says:
    July 5th, 2008 at 10:01 am

    @BVK Chaitanya
    Cool, I was pretty sure that other people are doing similar things. Let me know if you come up with any cool tips/tricks. I’ve started signing the revisions using hg sign like one commenter suggested already.

  10. Binny V A Says:
    July 5th, 2008 at 10:37 am

    There is another option - you can publish you dot files in a site like http://dotfiles.org/

  11. Yi Qiang Says:
    July 5th, 2008 at 10:51 am

    dotfiles.org provides absolutely no revision control :-)

  12. BVK Chaitanya Says:
    July 6th, 2008 at 12:15 am

    @YiQiang
    Yeah, i too should give hg sign a shot. But it seems it doesn’t restrict users from cloning your repository.

    I want mercurial plugins/options to keep repositories in encrypted format. This will let me keep dotfiles with passwords (like .authinfo) too. Then i don’t need to bother with signing patches at all, who ever can clone can commit.

    BTW, my DVCS knowledge is too limited, so i don’t know whether such a feature makes any sense or not :)

  13. Yi Qiang Says:
    July 6th, 2008 at 10:55 am

    @BVK
    Well, if you didn’t want people to clone your repository, you should probably just put your files somewhere secret :)

    As for the encrypted format, I googled around a bit and I don’t think hg has that functionality, do any other DVCS have that?

  14. numerodix Says:
    July 6th, 2008 at 11:45 am

    A bit simplistic imo. For one thing you assume you have hg (or your vcs of choice) everywhere you go. Here’s mine:
    http://www.matusiak.eu/numerodix/blog/index.php/2007/07/27/using-your-dotfiles-on-the-go/

  15. Yi Qiang Says:
    July 6th, 2008 at 11:54 am

    @numerodix
    Cool, I checked out your solution and it definitely is portable, just depends on some shell scripts + gnu tools installed. For my own personal use however, having revision control is more important and i can install hg on any machine that has python, which is quite common these days.

  16. Dan Hirsch Says:
    July 7th, 2008 at 10:24 pm

    I tend to do something very similar, except I use git and put the files in a directory named “…” (eg, “~/.zshrc” is in “~/…/zshrc”). This has the advantage of standing out in a directory listing.

    I also occasionally tar up the repository and make it available for download (via scp), in case I don’t have git handy.

Leave a Reply

Icons by N.Design Studio. Designed By Ben Swift. Powered by WordPress and Free WordPress Themes
Entries RSS Comments RSS Log in