source: dotfiles/guix/.config/i3blocks/temp@ 53e5e13

Last change on this file since 53e5e13 was 53e5e13, checked in by Mikhail Kirillov <w96k@…>, on Mar 12, 2020 at 7:22:49 PM

Add i3blocks bar for sway

  • Property mode set to 100755
File size: 1.9 KB
RevLine 
[53e5e13]1#!/usr/bin/env perl
2# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
3# Copyright 2014 Vivien Didelot <vivien@didelot.org>
4# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
5# Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr>
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20use strict;
21use warnings;
22use utf8;
23use Getopt::Long;
24
25binmode(STDOUT, ":utf8");
26
27# default values
28my $t_warn = $ENV{T_WARN} || 70;
29my $t_crit = $ENV{T_CRIT} || 90;
30my $chip = $ENV{SENSOR_CHIP} || "";
31my $temperature = -9999;
32
33sub help {
34 print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
35 print "-w <percent>: warning threshold to become yellow\n";
36 print "-c <percent>: critical threshold to become red\n";
37 print "--chip <chip>: sensor chip\n";
38 exit 0;
39}
40
41GetOptions("help|h" => \&help,
42 "w=i" => \$t_warn,
43 "c=i" => \$t_crit,
44 "chip=s" => \$chip);
45
46# Get chip temperature
47open (SENSORS, "sensors -u $chip |") or die;
48while (<SENSORS>) {
49 if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
50 $temperature = $1;
51 last;
52 }
53}
54close(SENSORS);
55
56$temperature eq -9999 and die 'Cannot find temperature';
57
58# Print short_text, full_text
59print "$temperature°C\n" x2;
60
61# Print color, if needed
62if ($temperature >= $t_crit) {
63 print "#FF0000\n";
64 exit 33;
65} elsif ($temperature >= $t_warn) {
66 print "#FFFC00\n";
67}
68
69exit 0;
Note: See TracBrowser for help on using the repository browser.