use utf8;
use strict;
use warnings;
use Perl6::Slurp;
use Encode;
use Text::Wrap;
my $maxCols = 76;
my $signature = "$eNV{HOME}/.signature";
my $taglines = "$eNV{HOME}/.taglines";
$text::Wrap::columns = $maxCols;
my $tag = `random-line < $taglines`;
$tag = decode_utf8($tag);
chomp $tag;
my $sig = slurp $signature or die "cannot open `$signature'n";
chomp $sig;
my $out = $sig . " | " . $tag;
$out = $sig . "n" . wrap("", "", $tag) if length $out > $maxCols;
if (system("mpc status | head -2 | tail -1 | grep -q '^\playing\'") == 0) {
# FIXME: Deal better with empty tags
my $info = `mpc -f "Listening to: ‘%title%’ from ‘%album%’ (%artist%)" status | head -n1`;
$out .= "n" . $info . wrap("", "", "");
}
binmode(STDOUT, ":utf8");
print $out;