Skip to content

Instantly share code, notes, and snippets.

@mxey
Created January 28, 2011 18:02
Show Gist options
  • Select an option

  • Save mxey/800660 to your computer and use it in GitHub Desktop.

Select an option

Save mxey/800660 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Modern::Perl;
#use lib '/home/mxey/code/AnyEvent-MPD/lib';
use autodie qw(:all);
use AnyEvent;
use AnyEvent::Handle;
use AnyEvent::Socket;
#use AnyEvent::MPD;
use IO::Handle;
use POSIX qw(strftime);
my ($np, $battery, $clock) = (('unknown') x 3);
#my $mpd = AnyEvent::MPD->new($ENV{MPD_HOST}, $ENV{MPD_PORT});
open(my $dzen, '|dzen2 -bg black -fg grey -fn fixed -ta r -x 500');
sub redraw {
my @parts = (
# "^fg(orange)$np^fg()",
"^fg(yellow3)$battery^fg()",
"^fg(green3)$clock^fg()",
);
$dzen->autoflush(1);
$dzen->say(join ' | ', @parts);
}
#sub mpd_change {
#my $status = $mpd->status->recv();
#my $currentsong = $mpd->currentsong->recv();
#if ($status->{state} eq 'play') {
#if ($currentsong->{Artist} && $currentsong->{Title}) {
#$np = $currentsong->{Artist}.' - '.$currentsong->{Title};
#} else {
#$np = $currentsong->{file};
#}
#} else {
#$np = 'NULL';
#}
#redraw();
#}
#$mpd->connect()->recv();
#mpd_change();
my $battery_watcher = AE::timer(1, 60, sub {
chomp($battery = `acpi -b`);
$battery //= 'unknown';
redraw();
});
my $clock_watcher = AE::timer(0, 1, sub {
$clock = strftime('%a, %d %b %Y %H:%M:%S %z', localtime());
redraw();
});
redraw();
while (1) {
#$mpd->idle()->recv();
#mpd_change();
AnyEvent->condvar->recv;
}
close($dzen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment