aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
committerclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
commitd2d735742ca61b211c9b48a2209d36395daebcf4 (patch)
treebda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_battery1
parenta6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff)
downloaddotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_battery1')
-rw-r--r--dot_config/i3/scripts/executable_battery1114
1 files changed, 114 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_battery1 b/dot_config/i3/scripts/executable_battery1
new file mode 100644
index 0000000..3b9d5a7
--- /dev/null
+++ b/dot_config/i3/scripts/executable_battery1
@@ -0,0 +1,114 @@
1#!/usr/bin/perl
2#
3# Copyright 2014 Pierre Mavro <[email protected]>
4# Copyright 2014 Vivien Didelot <[email protected]>
5#
6# Licensed under the terms of the GNU GPL v3, or any later version.
7#
8# This script is meant to use with i3blocks. It parses the output of the "acpi"
9# command (often provided by a package of the same name) to read the status of
10# the battery, and eventually its remaining time (to full charge or discharge).
11#
12# The color will gradually change for a percentage below 85%, and the urgency
13# (exit code 33) is set if there is less that 5% remaining.
14
15# Edited by Andreas Lindlbauer <[email protected]>
16
17use strict;
18use warnings;
19use utf8;
20
21# otherwise we get in console "Wide character in print at"
22binmode(STDOUT, ':utf8');
23
24# my $acpi;
25my $upower;
26my $percent;
27my $bat_state;
28my $status;
29my $ac_adapt;
30my $full_text;
31my $short_text;
32my $label = '😅';
33my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
34
35open (UPOWER, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'percentage' |") or die;
36$upower = <UPOWER>;
37close(UPOWER);
38
39# fail on unexpected output
40if ($upower !~ /: (\d+)%/) {
41 die "$upower\n";
42}
43
44$percent = $1;
45$full_text = "$percent%";
46
47open (BAT_STATE, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'state' |") or die;
48$bat_state = <BAT_STATE>;
49close(BAT_STATE);
50
51if ($bat_state !~ /: (\w+)/) {
52 die "$bat_state\n";
53}
54$status = $1;
55
56if ($status eq 'discharging') {
57 $full_text .= ' ';
58} elsif ($status eq 'charging') {
59 $full_text .= ' ';
60} elsif ($status eq 'Unknown') {
61 open (AC_ADAPTER, "acpi -a |") or die;
62 $ac_adapt = <AC_ADAPTER>;
63 close(AC_ADAPTER);
64
65 if ($ac_adapt =~ /: ([\w-]+)/) {
66 $ac_adapt = $1;
67
68 if ($ac_adapt eq 'on-line') {
69 $full_text .= ' CHR';
70 } elsif ($ac_adapt eq 'off-line') {
71 $full_text .= ' DIS';
72 }
73 }
74}
75
76$short_text = $full_text;
77
78if ($percent < 20) {
79 $label = '';
80} elsif ($percent < 45) {
81 $label = '';
82} elsif ($percent < 70) {
83 $label = '';
84} elsif ($percent < 95) {
85 $label = '';
86} else {
87 $label = '';
88}
89
90# print text
91print " ${label}";
92print " $full_text\n";
93print " ${label}";
94print " $short_text\n";
95
96# consider color and urgent flag only on discharge
97if ($status eq 'discharging') {
98
99 if ($percent < 20) {
100 print "#FF0000\n";
101 } elsif ($percent < 40) {
102 print "#FFAE00\n";
103 } elsif ($percent < 60) {
104 print "#FFF600\n";
105 } elsif ($percent < 85) {
106 print "#A8FF00\n";
107 }
108
109 if ($percent < 5) {
110 exit(33);
111 }
112}
113
114exit(0);
Powered by cgit v1.2.3 (git 2.41.0)