3 # Copyright (C) 2011-2012 Simon Ruderich
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 my $path = '/sys/class/power_supply/BAT0/uevent';
25 # No battery available.
30 my $screen_mode = (defined $ARGV[0] and $ARGV[0] eq '-s');
31 my $tmux_mode = (defined $ARGV[0] and $ARGV[0] eq '-t');
35 open my $file, '<', $path or die $!;
37 /^POWER_SUPPLY_([A-Z_]+)=(.+)$/;
40 close $file or die $!;
42 my $charge = int($battery{CHARGE_NOW} / $battery{CHARGE_FULL} * 100);
44 # GNU screen mode with colors: 0-20 red, 20-40 yellow, 40-100 green.
49 } elsif ($charge < 40) {
55 print "\005{+$color}$charge%\005{-}\n";
58 } elsif ($tmux_mode) {
62 } elsif ($charge < 40) {
68 print "#[fg=$color,bold]$charge%#[default]\n";