mirror of
https://github.com/bvanroll/_dotfiles.git
synced 2025-08-30 04:22:47 +00:00
init
This commit is contained in:
20
.config/i3blocks/battery/README.md
Normal file
20
.config/i3blocks/battery/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# battery
|
||||
|
||||
Show battery info.
|
||||
|
||||

|
||||
|
||||
# Dependencies
|
||||
|
||||
* `acpi`
|
||||
|
||||
# Config
|
||||
|
||||
```
|
||||
[battery]
|
||||
command=$SCRIPT_DIR/battery
|
||||
interval=30
|
||||
LABEL=BAT
|
||||
#LABEL=⚡
|
||||
#BAT_NUMBER=0
|
||||
```
|
94
.config/i3blocks/battery/battery
Executable file
94
.config/i3blocks/battery/battery
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env perl
|
||||
#
|
||||
# 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;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
my $acpi;
|
||||
my $status;
|
||||
my $percent;
|
||||
my $ac_adapt;
|
||||
my $full_text;
|
||||
my $short_text;
|
||||
my $bat_number = $ENV{BAT_NUMBER} || 0;
|
||||
my $label = $ENV{LABEL} || "";
|
||||
|
||||
# read the first line of the "acpi" command output
|
||||
open (ACPI, "acpi -b 2>/dev/null| grep 'Battery $bat_number' |") or die;
|
||||
$acpi = <ACPI>;
|
||||
close(ACPI);
|
||||
|
||||
# fail on unexpected output
|
||||
if (not defined($acpi)) {
|
||||
# don't print anything to stderr if there is no battery
|
||||
exit(0);
|
||||
}
|
||||
elsif ($acpi !~ /: ([\w\s]+), (\d+)%/) {
|
||||
die "$acpi\n";
|
||||
}
|
||||
|
||||
$status = $1;
|
||||
$percent = $2;
|
||||
$full_text = "$label$percent%";
|
||||
|
||||
if ($status eq 'Discharging') {
|
||||
$full_text .= ' DIS';
|
||||
} elsif ($status eq 'Charging') {
|
||||
$full_text .= ' CHR';
|
||||
} elsif ($status eq 'Unknown') {
|
||||
open (AC_ADAPTER, "acpi -a |") or die;
|
||||
$ac_adapt = <AC_ADAPTER>;
|
||||
close(AC_ADAPTER);
|
||||
|
||||
if ($ac_adapt =~ /: ([\w-]+)/) {
|
||||
$ac_adapt = $1;
|
||||
|
||||
if ($ac_adapt eq 'on-line') {
|
||||
$full_text .= ' CHR';
|
||||
} elsif ($ac_adapt eq 'off-line') {
|
||||
$full_text .= ' DIS';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$short_text = $full_text;
|
||||
|
||||
if ($acpi =~ /(\d\d:\d\d):/) {
|
||||
$full_text .= " ($1)";
|
||||
}
|
||||
|
||||
# print text
|
||||
print "$full_text\n";
|
||||
print "$short_text\n";
|
||||
|
||||
# consider color and urgent flag only on discharge
|
||||
if ($status eq 'Discharging') {
|
||||
|
||||
if ($percent < 20) {
|
||||
print "#FF0000\n";
|
||||
} elsif ($percent < 40) {
|
||||
print "#FFAE00\n";
|
||||
} elsif ($percent < 60) {
|
||||
print "#FFF600\n";
|
||||
} elsif ($percent < 85) {
|
||||
print "#A8FF00\n";
|
||||
}
|
||||
|
||||
if ($percent < 5) {
|
||||
exit(33);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
BIN
.config/i3blocks/battery/battery.png
Normal file
BIN
.config/i3blocks/battery/battery.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
6
.config/i3blocks/battery/i3blocks.conf
Normal file
6
.config/i3blocks/battery/i3blocks.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
[battery]
|
||||
command=$SCRIPT_DIR/battery
|
||||
interval=30
|
||||
LABEL=BAT
|
||||
#LABEL=⚡
|
||||
#BAT_NUMBER=0
|
Reference in New Issue
Block a user