diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2022-09-14 15:31:02 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2022-09-14 15:31:02 +0100 |
commit | 6fe0ac8e2f06cd198c53cdc17048756572604e20 (patch) | |
tree | 5ae2dedab837da0c15d8c1f61237982196e1eab5 /dayplan.pl | |
parent | 533d91f366da5d2b5389c87c5e25d01a65bcdce6 (diff) |
porting dayplan.zsh to perl
Diffstat (limited to '')
-rw-r--r-- | dayplan.pl | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/dayplan.pl b/dayplan.pl new file mode 100644 index 0000000..0cf3d4e --- /dev/null +++ b/dayplan.pl @@ -0,0 +1,61 @@ +# Porting dayplan.ksh to Perl + +use strict; +use warnings; +use DateTime; + + +my $numargs = $#ARGV + 1; +my $fp = "/tmp"; + +my ($dt, $d, $y, $m, $weekday); + +my @weekdays = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); + +if ($numargs == 1) { + ($y, $m, $d) = $ARGV[0] =~ /(\d\d\d\d)-(\d\d)-(\d\d)/; + $dt = DateTime->new( + year => $y, + month => $m, + day => $d + ); + $weekday = $weekdays[$dt->day_of_week]; + # print "year: $y, month: $m, day: $d, day of week: $weekday", "\n"; +} +else { + $dt = DateTime->now; + $d = $dt->day; + $m = $dt->month; + $y = $dt->year; + $weekday = $weekdays[$dt->day_of_week]; +} + +my $template = " +Goal for $weekday: [replace this with your goal] +--- + +08:15 - 08:20 - Harvey to school +08:45 - 09:00 - Sophie to school +09:15 - 09:30 - Email +09:30 - 10:00 - +10:00 - 11:00 - +11:00 - 12:00 - +12:15 - 13:00 - Lunch +13:00 - 14:00 - +14:00 - 15:00 - +15:00 - 16:00 - +16:00 - 17:00 - +"; + +my $today_planner = sprintf("%s/%d-%02d-%02d.txt", $fp,$y,$m,$d); +if (-e $today_planner) { + exec("vim", "$today_planner"); +} else +{ + open( FH, ">$today_planner"); + print FH $template; + close FH; + exec("vim", "$today_planner"); +} + + |