diff options
author | clarkzjw <[email protected]> | 2022-11-17 10:56:25 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2022-11-17 10:56:25 -0800 |
commit | d2d735742ca61b211c9b48a2209d36395daebcf4 (patch) | |
tree | bda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_battery1 | |
parent | a6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff) | |
download | dotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz |
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_battery1')
-rw-r--r-- | dot_config/i3/scripts/executable_battery1 | 114 |
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 | |||
17 | use strict; | ||
18 | use warnings; | ||
19 | use utf8; | ||
20 | |||
21 | # otherwise we get in console "Wide character in print at" | ||
22 | binmode(STDOUT, ':utf8'); | ||
23 | |||
24 | # my $acpi; | ||
25 | my $upower; | ||
26 | my $percent; | ||
27 | my $bat_state; | ||
28 | my $status; | ||
29 | my $ac_adapt; | ||
30 | my $full_text; | ||
31 | my $short_text; | ||
32 | my $label = '😅'; | ||
33 | my $bat_number = $ENV{BLOCK_INSTANCE} || 0; | ||
34 | |||
35 | open (UPOWER, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'percentage' |") or die; | ||
36 | $upower = <UPOWER>; | ||
37 | close(UPOWER); | ||
38 | |||
39 | # fail on unexpected output | ||
40 | if ($upower !~ /: (\d+)%/) { | ||
41 | die "$upower\n"; | ||
42 | } | ||
43 | |||
44 | $percent = $1; | ||
45 | $full_text = "$percent%"; | ||
46 | |||
47 | open (BAT_STATE, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'state' |") or die; | ||
48 | $bat_state = <BAT_STATE>; | ||
49 | close(BAT_STATE); | ||
50 | |||
51 | if ($bat_state !~ /: (\w+)/) { | ||
52 | die "$bat_state\n"; | ||
53 | } | ||
54 | $status = $1; | ||
55 | |||
56 | if ($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 | |||
78 | if ($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 | ||
91 | print " ${label}"; | ||
92 | print " $full_text\n"; | ||
93 | print " ${label}"; | ||
94 | print " $short_text\n"; | ||
95 | |||
96 | # consider color and urgent flag only on discharge | ||
97 | if ($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 | |||
114 | exit(0); | ||