update battery and storage block
This commit is contained in:
parent
785b041b0c
commit
d45c6ba7fe
102
battery
102
battery
@ -1,78 +1,40 @@
|
|||||||
#!/usr/bin/perl
|
#!/bin/bash
|
||||||
#
|
|
||||||
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
|
|
||||||
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
|
|
||||||
#
|
|
||||||
# Licensed under the terms of the GNU GPL v3, or any later version.
|
|
||||||
#
|
|
||||||
# This script is meant to use with i3blocks. It parses the output of the "acpi"
|
|
||||||
# command (often provided by a package of the same name) to read the status of
|
|
||||||
# the battery, and eventually its remaining time (to full charge or discharge).
|
|
||||||
#
|
|
||||||
# The color will gradually change for a percentage below 85%, and the urgency
|
|
||||||
# (exit code 33) is set if there is less that 5% remaining.
|
|
||||||
|
|
||||||
use strict;
|
[[ ${BLOCK_INSTANCE} == '' ]] && BATTERY=0 || BATTERY=${BLOCK_INSTANCE}
|
||||||
use warnings;
|
cat /sys/class/power_supply/BAT${BATTERY}/uevent | gawk -F '=' '
|
||||||
use utf8;
|
/POWER_SUPPLY_STATUS=/ {
|
||||||
|
status=$2
|
||||||
my $acpi;
|
|
||||||
my $status;
|
|
||||||
my $percent;
|
|
||||||
my $full_text;
|
|
||||||
my $short_text;
|
|
||||||
my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
|
|
||||||
|
|
||||||
# read the first line of the "acpi" command output
|
|
||||||
open (ACPI, "acpi -b | grep 'Battery $bat_number' |") or die;
|
|
||||||
$acpi = <ACPI>;
|
|
||||||
close(ACPI);
|
|
||||||
|
|
||||||
# fail on unexpected output
|
|
||||||
if ($acpi !~ /: (\w+), (\d+)%/) {
|
|
||||||
die "$acpi\n";
|
|
||||||
}
|
}
|
||||||
|
/POWER_SUPPLY_ENERGY_FULL=/ {
|
||||||
$status = $1;
|
efull=$2
|
||||||
$percent = $2;
|
|
||||||
|
|
||||||
if ($status eq 'Discharging') {
|
|
||||||
$full_text = '↓';
|
|
||||||
} elsif ($status eq 'Charging') {
|
|
||||||
$full_text = '⚡';
|
|
||||||
}
|
}
|
||||||
|
/POWER_SUPPLY_ENERGY_NOW=/ {
|
||||||
|
enow=$2
|
||||||
$short_text = $full_text;
|
}
|
||||||
|
END {
|
||||||
if ($acpi =~ /(\d\d:\d\d):/) {
|
charge=enow/efull*100
|
||||||
$full_text .= " $1";
|
if (status == "Discharging") {
|
||||||
|
status="↓"
|
||||||
|
} else if (status == "Charging") {
|
||||||
|
status="↑"
|
||||||
} else {
|
} else {
|
||||||
$full_text .= "$percent%";
|
status=""
|
||||||
}
|
}
|
||||||
|
printf("%s%d%", status, charge)
|
||||||
# print text
|
print("\n")
|
||||||
print "$full_text\n";
|
if (charge < 20) {
|
||||||
print "$short_text\n";
|
print("#FF0000\n")
|
||||||
|
} else if (charge < 40) {
|
||||||
# consider color and urgent flag only on discharge
|
print("#FFAE00\n")
|
||||||
#if ($status eq 'Discharging') {
|
} else if (charge < 60) {
|
||||||
|
print("#FFF600\n")
|
||||||
if ($percent < 20) {
|
} else if (charge < 85) {
|
||||||
print "#FF0000\n";
|
print("#A8FF00\n")
|
||||||
} elsif ($percent < 40) {
|
|
||||||
print "#FFAE00\n";
|
|
||||||
} elsif ($percent < 60) {
|
|
||||||
print "#FFF600\n";
|
|
||||||
} elsif ($percent < 85) {
|
|
||||||
print "#A8FF00\n";
|
|
||||||
} else {
|
} else {
|
||||||
print "#04B431\n";
|
print("#04B431\n")
|
||||||
}
|
}
|
||||||
|
if (charge < 5) {
|
||||||
if ($percent < 5) {
|
exit 33
|
||||||
exit(33);
|
|
||||||
}
|
}
|
||||||
#}
|
}
|
||||||
|
'
|
||||||
exit(0);
|
|
||||||
|
20
storage
20
storage
@ -5,12 +5,20 @@ df | gawk '
|
|||||||
sfm=$4/1024
|
sfm=$4/1024
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
if (sfg > 5) { printf("%.1f GB", sfg) }
|
if (sfg > 5) {
|
||||||
else { printf( "%.0f MB", sfm ) }
|
printf("%.1f GB", sfg)
|
||||||
|
} else {
|
||||||
|
printf("%.0f MB", sfm)
|
||||||
|
}
|
||||||
print("\n")
|
print("\n")
|
||||||
if (sfg > 15) { print("#04B431\n") }
|
if (sfg > 15) {
|
||||||
else if (sfg > 5) { print("#FFA500\n") }
|
print("#04B431\n")
|
||||||
else if (sfg > 1) { print("#FF0000\n") }
|
} else if (sfg > 5) {
|
||||||
else { exit 33 }
|
print("#FFA500\n")
|
||||||
|
} else if (sfg > 1) {
|
||||||
|
print("#FF0000\n")
|
||||||
|
} else {
|
||||||
|
exit 33
|
||||||
|
}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user