dotfiles/dot_config/i3/bin/executable_i3blocks-battery
Felix Delattre 2359ed01a8 Update .chezmoiignore
Update .config/helix/config.toml
Update .config/helix/languages.toml
Update .config/i3/bin/brightness.sh
Update .config/i3/bin/exit.sh
Update .config/i3/bin/i3.config.keycodes
Update .config/i3/bin/i3blocks-battery
Update .config/i3/bin/lock.sh
Update .config/i3/bin/monitor.sh
Update .config/i3/bin/toggletouchpad.sh
Update .config/i3/config
Update .config/i3/i3blocks.conf
Update .config/i3/i3status.conf
Update .config/lvim/config.lua
Update .config/spacebar/spacebarrc
Update .config/sway/bin/brightness.sh
Update .config/sway/bin/i3blocks-battery
Update .config/sway/bin/toggletouchpad.sh
Update .config/sway/blocks.conf
Update .config/sway/config
Update .config/sway/wallpaper.jpg
Update .gitconfig
Update .oh-my-zsh/custom/aliases.zsh
Update .oh-my-zsh/custom/linux.zsh
Update .oh-my-zsh/custom/mac.zsh
Update .oh-my-zsh/custom/prompt.zsh
Update .skhdrc
Update .tmux.conf
Update .vimrc
Update .zshrc
Update backup.sh
Update .yabairc
2023-11-07 23:08:21 +00:00

61 lines
1.1 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
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";
}
$status = $1;
$percent = $2;
$full_text = "";
if ($status eq 'Discharging') {
$full_text .= "⚡ $percent%";
if ($acpi =~ /(\d\d:\d\d):/) {
$full_text .= " ($1)";
}
} elsif ($status eq 'Charging') {
$full_text .= " $percent%";
}
elsif ($status eq 'Unknown' || $status eq 'Full') {
$full_text .= "⚡ $percent%";
}
# 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);