Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. #!/usr/bin/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. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. use warnings;
  18. use utf8;
  19. use Getopt::Long;
  20. binmode(STDOUT, ":utf8");
  21. # default values
  22. my $t_warn = 70;
  23. my $t_crit = 90;
  24. my $chip = "";
  25. my $temperature = -9999;
  26. sub help {
  27. print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
  28. print "-w <percent>: warning threshold to become yellow\n";
  29. print "-c <percent>: critical threshold to become red\n";
  30. print "--chip <chip>: sensor chip\n";
  31. exit 0;
  32. }
  33. GetOptions("help|h" => \&help,
  34. "w=i" => \$t_warn,
  35. "c=i" => \$t_crit,
  36. "chip=s" => \$chip);
  37. # Get chip temperature
  38. open (SENSORS, "sensors -u $chip |") or die;
  39. while (<SENSORS>) {
  40. if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
  41. $temperature = $1;
  42. last;
  43. }
  44. }
  45. close(SENSORS);
  46. $temperature eq -9999 and die 'Cannot find temperature';
  47. # Print short_text, full_text
  48. print "$temperature°C\n" x2;
  49. # Print color, if needed
  50. if ($temperature >= $t_crit) {
  51. print "#FF0000\n";
  52. exit 33;
  53. } elsif ($temperature >= $t_warn) {
  54. print "#FFFC00\n";
  55. }
  56. exit 0;