diff --git a/install.pl b/install.pl index df39665..a65c0cf 100755 --- a/install.pl +++ b/install.pl @@ -86,6 +86,13 @@ my %links = ( gdbinit => '.gdbinit', ); +my $contained = (substr $scriptdir, 0, length($home)) eq $home; +my $prefix = undef; +if ($contained) { + $prefix = substr $scriptdir, length($home); + ($prefix) = $prefix =~ m{^\/? (.+)? [^/]+ $}x; +} + my $i = 0; # Keep track of how many links we added for my $file (keys %links) { # See if this file resides in a directory, and create it if needed. @@ -108,6 +115,15 @@ for my $file (keys %links) { unlink($dest) || warn "Couldn't unlink '$dest': $!\n"; } + if ($contained) { + chdir $home; + $dest = "$links{$file}"; + $src = "$prefix$file"; + if ($path) { + $src = "../$src"; + } + } + symlink($src => $dest) ? $i++ : warn "Couldn't link '$src' to '$dest': $!\n"; }