From d2d735742ca61b211c9b48a2209d36395daebcf4 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 17 Nov 2022 10:56:25 -0800 Subject: + add existing config --- dot_config/i3/scripts/executable_temperature | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 dot_config/i3/scripts/executable_temperature (limited to 'dot_config/i3/scripts/executable_temperature') diff --git a/dot_config/i3/scripts/executable_temperature b/dot_config/i3/scripts/executable_temperature new file mode 100644 index 0000000..4e31610 --- /dev/null +++ b/dot_config/i3/scripts/executable_temperature @@ -0,0 +1,86 @@ +#!/usr/bin/env perl +# Copyright 2014 Pierre Mavro +# Copyright 2014 Vivien Didelot +# Copyright 2014 Andreas Guldstrand +# Copyright 2014 Benjamin Chretien + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Edited by Andreas Lindlbauer + +use strict; +use warnings; +use utf8; +use Getopt::Long; + +binmode(STDOUT, ":utf8"); + +# default values +my $t_warn = $ENV{T_WARN} || 70; +my $t_crit = $ENV{T_CRIT} || 90; +my $chip = $ENV{SENSOR_CHIP} || ""; +my $temperature = -9999; +my $label = "😀 "; + +sub help { + print "Usage: temperature [-w ] [-c ] [--chip ]\n"; + print "-w : warning threshold to become yellow\n"; + print "-c : critical threshold to become red\n"; + print "--chip : sensor chip\n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit, + "chip=s" => \$chip); + +# Get chip temperature +open (SENSORS, "sensors -u $chip |") or die; +while () { + if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) { + $temperature = $1; + last; + } +} +close(SENSORS); + +$temperature eq -9999 and die 'Cannot find temperature'; + +if ($temperature < 45) { + $label = ''; +} elsif ($temperature < 55) { + $label = ''; +} elsif ($temperature < 65) { + $label = ''; +} elsif ($temperature < 75) { + $label = ''; +} else { + $label = ''; +} +# Print short_text, full_text +print "${label}"; +print " $temperature°C\n"; +print "${label}"; +print " $temperature°C\n"; + +# Print color, if needed +if ($temperature >= $t_crit) { + print "#FF0000\n"; + exit 33; +} elsif ($temperature >= $t_warn) { + print "#FFFC00\n"; +} + +exit 0; -- cgit v1.2.3