Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 96 lines (85 sloc) 2.01 KB
#! /usr/bin/perl -w
use strict;
use File::Copy;
use File::Path qw(make_path);
sub file_names
{
return qw{
.ackrc
.bash_profile
.bashrc
bash_completion
.dir_colors
.gemrc
.gitconfig
.gitignore
.git-completion.sh
.inputrc
.irbrc
.irssi
.rdebugrc
.rvmrc
.screenrc
.sh_aliases
.shrc
.tmux.conf
.vim
.vimrc
.vimrc_files
.zprofile
.zshrc
.zshenv
bin/diff_painter.pl
bin/tree.sh
bin/tpm
bin/tpc
bin/tpi
bin/tpcert
bin/hub
bin/bundle-update-lockfile
bin/git-checkout-by-match
bin/git-large
bin/git-obliterate
bin/git-rmbranch
bin/git-rmstale
bin/git-stale-remote-branches
bin/redmine-ticket-status
.completion
soloistrc
Cheffile
Cheffile.lock
};
}
link_files();
sub get_timestamp {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($mon < 10) { $mon = "0$mon"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$year=$year+1900;
return $year . $mon . $mday . '_' . $hour . '_' . $min;
}
sub file_links
{
my %file_links = map {glob("~/$_") => glob("~/config-files/$_")} file_names();
return %file_links;
}
sub link_files
{
make_path(glob('~/bin'));
my %file_links = file_links();
my $backup_date = get_timestamp();
for my $file (keys %file_links) {
if (-l $file) {
unlink $file;
} elsif (-e $file) {
move($file, "${file}.${backup_date}");
print("Backed up $file to ${file}.${backup_date}\n");
}
my $symlink_exists = eval { symlink($file_links{$file}, $file); 1 };
die "Symlinking no workie" unless $symlink_exists;
}
print "\nLinking Complete\n";
print "$_\n" for file_names();
}