about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-10-08 00:37:01 +0530
committerAndinus <andinus@nand.sh>2020-10-08 00:37:01 +0530
commit69f17fe584d24a34b6d826780343819bdbcc3ccc (patch)
tree0cb277874227c467303fe36dcf1c3121672102a6
parent574684fca66be90f789e5dbf5fd1a2bacaf84201 (diff)
downloadleo-69f17fe584d24a34b6d826780343819bdbcc3ccc.tar.gz
Get $backup_dir from config, format $mday with 2 leading zeros
This will not work with previous configs. But that's fine because I'm
the only one using this.
-rwxr-xr-xleo.pl15
-rw-r--r--share/config.pl1
2 files changed, 10 insertions, 6 deletions
diff --git a/leo.pl b/leo.pl
index fcf3bef..dcb8447 100755
--- a/leo.pl
+++ b/leo.pl
@@ -19,18 +19,20 @@ GetOptions(
     qw{ verbose encrypt sign delete help }
 ) or die "Error in command line arguments\n";
 
-my $ymd = ymd(); # YYYY-MM-DD.
-my $backup_dir = "/tmp/backups/$ymd";
-
-path($backup_dir)->mkpath; # Create backup directory.
-my $prof;
-
 # Config file for leo.
 my $config_file = $ENV{XDG_CONFIG_HOME} || "$ENV{HOME}/.config";
 $config_file .= "/leo.pl";
 
 require "$config_file";
 
+my $ymd = ymd(); # YYYY-MM-DD.
+my $backup_dir = get_backup_dir() || "/tmp/backups";
+$backup_dir .= "/$ymd";
+
+path($backup_dir)->mkpath; # Create backup directory.
+my $prof;
+
+
 my %profile = get_profile();
 my $gpg_fingerprint = get_gpg_fingerprint();
 my $gpg_bin = get_gpg_bin();
@@ -145,5 +147,6 @@ sub ymd {
     my @months = qw( 01 02 03 04 05 06 07 08 09 10 11 12 );
     my $month = $months[$mon];
 
+    $mday = sprintf "%02d", $mday;
     return "$year-$month-$mday";
 }
diff --git a/share/config.pl b/share/config.pl
index caee891..7d542f3 100644
--- a/share/config.pl
+++ b/share/config.pl
@@ -31,5 +31,6 @@ $profile{mozilla} = $profile{".mozilla"};
 sub get_gpg_fingerprint { return $gpg_fingerprint; }
 sub get_profile { return %profile; }
 sub get_gpg_bin { return $gpg_bin; }
+sub get_backup_dir { return "/tmp/backups" }
 
 1;