aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-08-27 16:55:55 +0530
committerAndinus <andinus@nand.sh>2020-08-27 16:55:55 +0530
commit6dca06c14e9019aa4c4e36697c22adc8a7f2f5f0 (patch)
treee92fbe8656132a5cbefe501d3e13e87e1c5e439e
parenteda386d91631ca79582b240f3be8fbe85beb4ec9 (diff)
downloadleo-6dca06c14e9019aa4c4e36697c22adc8a7f2f5f0.tar.gz
Make all paths relative to $HOME, add emacs & config to dispatch
I'm trying to make it easier to print help message, I don't want to print it manually. After this I'll just turn the dispatch table into just table which contains all the paths to be archived & then I'll be able to print help nicely.
-rwxr-xr-xleo.pl50
1 files changed, 20 insertions, 30 deletions
diff --git a/leo.pl b/leo.pl
index 7468e54..74055ac 100755
--- a/leo.pl
+++ b/leo.pl
@@ -22,43 +22,45 @@ my $gpg_fingerprint = "D9AE4AEEE1F1B3598E81D9DFB67D55D482A799FD";
my $archive_dir = "/tmp/archive";
my $ymd = ymd(); # YYYY-MM-DD.
-# Dispatch table.
+# Dispatch table. All paths should be relative to $ENV{HOME}.
my %dispatch = (
journal => sub {
my $tmp = $options{encrypt} and undef $options{encrypt}
if $options{encrypt};
archive("$archive_dir/journal_$ymd.tar",
- "-C", "$ENV{HOME}/documents",
- "andinus.org.gpg", "archive.org.gpg");
+ "documents/andinus.org.gpg", "documents/archive.org.gpg");
$options{encrypt} = $tmp;
},
+ emacs => sub {
+ archive("$archive_dir/emacs_$ymd.tar", ".emacs.d", ".elfeed",
+ ".org-timestamps");
+ },
+ config => sub {
+ archive("$archive_dir/config_$ymd.tar",
+ qw{ .config .kshrc .kshrc.d .tmux.conf .xsession
+ .screenlayout .mg .mbsyncrc .fehbg .profile .remind
+ .plan .authinfo.gpg .Xresources });
+ },
);
-# These are the directories to be added to dispatch table but have
-# path names different from their profile names.
+# This adds directories with different profile name and path.
my %directories = (
ssh => "$ENV{HOME}/.ssh",
pass => "$ENV{HOME}/.password-store",
mozilla => "$ENV{HOME}/.mozilla",
- config => "$ENV{HOME}/.config",
- emacs => "$ENV{HOME}/.emacs.d",
- elfeed => "$ENV{HOME}/.elfeed",
);
foreach my $dir (sort keys %directories) {
$dispatch{$dir} = sub {
- archive("$archive_dir/${dir}_${ymd}.tar",
- "-C", "$directories{$dir}", ".");
+ archive("$archive_dir/${dir}_${ymd}.tar", "$directories{$dir}");
};
}
-# This adds the directories that have same path relative to $ENV{HOME}
-# as profile name.
+# This adds the directories with same profile name as path.
foreach my $profile (qw( emails music projects documents videos pictures
downloads )) {
$dispatch{$profile} = sub {
- archive("$archive_dir/${profile}_$ymd.tar",
- "-C", "$ENV{HOME}/$profile", ".");
+ archive("$archive_dir/${profile}_$ymd.tar", $profile);
};
}
@@ -66,33 +68,21 @@ foreach my $profile (qw( emails music projects documents videos pictures
sub archive {
my $tar_file = shift @_;
- my ( $cwd, @archive_paths );
- # Passing `-C' won't print "tar: Removing leading / from absolute
- # path names in the archive" to STDERR in some cases.
- if ( $_[0] eq "-C" ) {
- $cwd = $_[1];
-
- # Remove `-C' & cwd to get @archive_paths;
- my @tmp = @_;
- shift @tmp; shift @tmp;
- @archive_paths = @tmp;
- } else {
- @archive_paths = @_;
- }
+ my @archive_paths = @_;
say "Archive: $tar_file";
warn "[WARN] $tar_file exists, might overwrite.\n" if -e $tar_file;
print "\n";
- tar_create($tar_file, @_);
+ tar_create($tar_file, "-C", $ENV{HOME}, @_);
$? # tar returns 1 on errors.
? die "Archive creation failed :: $?\n"
# Print absolute paths for all archived files/directories.
- : say path($_)->absolute($cwd), " archived."
+ : say path($_)->absolute($ENV{HOME}), " archived."
foreach @archive_paths;
- tar_list($tar_file) if $options{verbose};
+ print "\n" and tar_list($tar_file) if $options{verbose};
encrypt_sign($tar_file) if $options{encrypt} or $options{sign};
}