install
changeset 3 9441d280d863
child 4 f5f3abf44414
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/install	Sun Sep 01 12:10:43 2013 +0200
@@ -0,0 +1,39 @@
+#! /usr/bin/perl
+
+use 5.012;
+use warnings;
+use File::Basename;
+use File::Spec::Functions qw(catfile rel2abs abs2rel canonpath);
+use Sys::Hostname;
+use autodie;
+
+# list of files/dirs to exclude
+my @exclude = map { qr/$_/ } qw(
+    ^\.\.?$
+    ^\.hg$
+), basename $0;
+
+foreach my $this (grep { not $_ ~~ @exclude } glob('.*')) {
+
+    my $link = catfile $ENV{HOME}, $this;
+
+    given ($link) {
+	when (not -e) {
+	    { no autodie; unlink $link }   # may be necessary if it's a broken symlink
+	    symlink abs2rel($this, $ENV{HOME}) => $link;
+	    say "$link linked";
+	    next;
+	}
+	when(not -l) {
+	    warn "$link is not a link, skipping\n";
+	    next;
+	}
+	when(-l) {
+	    my $dst = rel2abs(readlink, $ENV{HOME});
+	    next if $dst eq rel2abs($this);
+	    warn "$link is a link to $dst, skipping\n";
+	    next;
+	}
+	default { ... }
+    }
+}