--- /dev/null
+#!/usr/bin/perl
+
+
+use strict;
+use warnings;
+
+
+my $path = '/sys/class/power_supply/BAT0/uevent';
+
+# No battery available.
+if (! -e $path) {
+ exit;
+}
+
+my $screen_mode = (defined $ARGV[0] and $ARGV[0] eq '-s');
+
+my %battery;
+
+open my $file, '<', $path;
+while (<$file>) {
+ /^POWER_SUPPLY_([A-Z_]+)=(.+)$/;
+ $battery{$1} = $2;
+}
+close $file;
+
+my $charge = int($battery{CHARGE_NOW} / $battery{CHARGE_FULL} * 100);
+
+# GNU screen mode with colors: 0-20 red, 20-40 yellow, 40-100 green.
+if ($screen_mode) {
+ my $color;
+ if ($charge < 20) {
+ $color = 'b r';
+ } elsif ($charge < 40) {
+ $color = 'b y';
+ } else {
+ $color = 'b g';
+ }
+
+ print "\005{+$color}$charge%\005{-}\n";
+
+# Just text output.
+} else {
+ print "$charge%\n";
+}
# for window borders in split mode).
sorendition = Bw
+# Display current battery charge if running on a laptop. Redisplay every 3
+# minutes.
+backtick 1 180 180 $HOME/.shell/bin/battery.pl -s # (BATTERY)
+
# Make sure the temporary variable we use is empty. Thanks to
# http://gist.github.com/133000 for the idea to use setenv and to TauPan in
# #screen on Freenode (2010-03-10 16:11 CET) for reminding me of it and
setenv s "$s%l" # - load average
setenv s "$s " # - space
setenv s "$s%H" # - hostname
+setenv s "$s " # - space (BATTERY)
+setenv s "$s%1`" # - battery status (BATTERY)
hardstatus alwayslastline "$s"
unsetenv s
sed 's/attrcolor b ".I"/#attrcolor b ".I"/' screenrc > screenrc.tmp
mv screenrc.tmp screenrc
fi
+# Display current battery charge on computers with a battery. Necessary lines
+# are marked as "(BATTERY)".
+if [ ! -d /sys/class/power_supply/BAT0 ]; then
+ echo screenrc: removing battery display
+ grep -v '(BATTERY)' screenrc > screenrc.tmp
+ mv screenrc.tmp screenrc
+fi
# Link setup for shells.
link shell ~/.shell