Created
February 9, 2020 18:24
-
-
Save zopsicle/54d1b4fe01d914c393e6a55ce9429b96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.12; | |
use warnings; | |
sub cmus | |
{ | |
my %stati = ( | |
playing => '>>', | |
paused => '||️', | |
stopped => '[]️', | |
); | |
my $status; | |
my $artist; | |
my $title; | |
for (qx{2>/dev/null cmus-remote --query}) { | |
chomp; | |
$status = $1 if /^status (.*)$/; | |
$artist = $1 if /^tag artist (.*)$/; | |
$title = $1 if /^tag title (.*)$/; | |
} | |
my @segments = ($artist, $stati{$status // ''}, $title); | |
join(' ', grep($_, @segments)); | |
} | |
sub battery | |
{ | |
my %stati = ( | |
'Charging' => '+', | |
'Discharging' => '-', | |
'Full' => '#', | |
); | |
my $status; | |
my $charge_full; | |
my $charge_now; | |
open(my $uevent, '<', '/sys/class/power_supply/BAT0/uevent'); | |
while (<$uevent>) { | |
chomp; | |
$status = $1 if /^POWER_SUPPLY_STATUS=(.*)$/; | |
$charge_full = $1 if /^POWER_SUPPLY_CHARGE_FULL=(.*)$/; | |
$charge_now = $1 if /^POWER_SUPPLY_CHARGE_NOW=(.*)$/; | |
} | |
my $charge = sprintf("%2.f%%", 100 * $charge_now / $charge_full); | |
join(' ', grep($_, $stati{$status // ''}, $charge)); | |
} | |
sub datetime | |
{ | |
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = | |
localtime(time); | |
sprintf("%04d-%02d-%02d @ %02d:%02d:%02d", | |
$year + 1900, $mon + 1, $mday, | |
$hour, $min, $sec); | |
} | |
sub main | |
{ | |
for (;;) { | |
sleep 1; | |
my @segments = (cmus, battery, datetime); | |
say(join(' ', grep($_, @segments))); | |
} | |
} | |
main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment