1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/usr/bin/env perl
use 5.038;
use utf8;
use Time::Piece;
sub span ($color, $text) {
return "<span foreground=\"$color\">$text</span>";
}
sub volume {
my ($volume) = `pactl get-sink-volume \@DEFAULT_SINK@` =~ /\s(\d+)%/;
chomp(my $mute = `pactl get-sink-mute \@DEFAULT_SINK@`);
my $symbol = '';
if ($mute eq 'Mute: yes') {
$symbol = '';
} elsif ($volume == 0) {
$symbol = '';
} elsif ($volume <= 50) {
$symbol = '';
}
return span('#ed8796', "$symbol $volume%");
}
sub network {
chomp(my $ssid = `iwgetid -r`);
my $symbol = $ssid ? ' ' : ' ';
return span('#f5a97f', "$symbol $ssid");
}
sub brightness {
my @brightness = split(/,/, `brightnessctl -m`);
return span('#eed49f', ' ' . $brightness[3]);
}
sub battery {
open my $cap_file, '<', '/sys/class/power_supply/BAT0/capacity' or die;
open my $status_file, '<', '/sys/class/power_supply/BAT0/status' or die;
chomp(my $capacity = <$cap_file>);
chomp(my $status = <$status_file>);
close $status_file;
close $cap_file;
my $symbol = '';
my $index = ($capacity - 1) / 10;
if ($status eq 'Discharging') {
my @symbols = (span('#ed8796', ''), '', '', '', '', '', '', '', '', '');
$symbol = $symbols[$index];
} elsif ($status eq 'Charging') {
my @symbols = ('', '', '', '', '', '', '', '', '', '');
$symbol = $symbols[$index];
} elsif ($status eq 'Full') {
$symbol = '';
}
return span('#a6da95', "$symbol $capacity%");
}
sub clock {
return span('#7dc4e4', ' ' . localtime()->strftime('%b %d %H:%M'));
}
while (1) {
my $status = join(' | ', volume, network, brightness, battery, clock);
$status = span('#cad3f5', $status);
say $status;
system('somebar', '-c', 'status', $status);
sleep 1;
}
|