#!/usr/bin/env perl # yis -- create this week's year-in-songs post # # in perl because ya know, it's in openbsd base # (and datemath in sh(1) is painful...) use strict; use warnings; use POSIX qw(strftime); use FindBin; use File::Basename; use Getopt::Long; my $repo = dirname($FindBin::RealBin); chdir $repo or die $!; my $wday = (localtime)[6]; my $sec_since_sun = $wday * 24 * 60 * 60; my $sundate = strftime "%Y-%m-%d", localtime(time - $sec_since_sun); GetOptions("d|date=s" => \$sundate) or die "usage error: $!\n"; die "usage: yis [-d|--date DATE] SONG by BAND\n" unless @ARGV; my $index; { open my $fh, "<", "yis/index.gph" or die $!; local $/; # enable slurp mode $index = <$fh>; close $fh; } my $nom = join(" ", @ARGV); my $title = "Week of $sundate: $nom"; (my $sep = $title) =~ s/./-/g; $index =~ s@^\[0\|\[@[0|[$sundate] $nom|/yis/${sundate}.txt|server|port]\n[0|[@m; open my $ifh, ">", "yis/index.gph" or die $!; print $ifh $index; close $ifh; open my $lfh, ">", "yis/$sundate.txt" or die $!; print $lfh "$title\n$sep\n"; close $lfh; my $editor = $ENV{EDITOR} ? $ENV{EDITOR} : "vi"; system($editor, "yis/$sundate.txt")