equal
deleted
inserted
replaced
|
1 #! /usr/bin/perl |
|
2 |
|
3 use 5.012; |
|
4 use warnings; |
|
5 use File::Basename; |
|
6 use File::Spec::Functions qw(catfile rel2abs abs2rel canonpath); |
|
7 use Sys::Hostname; |
|
8 use autodie; |
|
9 |
|
10 # list of files/dirs to exclude |
|
11 my @exclude = map { qr/$_/ } qw( |
|
12 ^\.\.?$ |
|
13 ^\.hg$ |
|
14 ), basename $0; |
|
15 |
|
16 foreach my $this (grep { not $_ ~~ @exclude } glob('.*')) { |
|
17 |
|
18 my $link = catfile $ENV{HOME}, $this; |
|
19 |
|
20 given ($link) { |
|
21 when (not -e) { |
|
22 { no autodie; unlink $link } # may be necessary if it's a broken symlink |
|
23 symlink abs2rel($this, $ENV{HOME}) => $link; |
|
24 say "$link linked"; |
|
25 next; |
|
26 } |
|
27 when(not -l) { |
|
28 warn "$link is not a link, skipping\n"; |
|
29 next; |
|
30 } |
|
31 when(-l) { |
|
32 my $dst = rel2abs(readlink, $ENV{HOME}); |
|
33 next if $dst eq rel2abs($this); |
|
34 warn "$link is a link to $dst, skipping\n"; |
|
35 next; |
|
36 } |
|
37 default { ... } |
|
38 } |
|
39 } |