Skip to content
Snippets Groups Projects
Commit 92c45c25 authored by Jens Nolte's avatar Jens Nolte
Browse files

Delete blocks that are no longer required

parent f15a8b5f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
#
# Copyright (C) 2016 James Murphy, 2018 Jens Nolte
# Licensed under the GPL version 2 only
#
# A battery indicator blocklet script for i3blocks
import re
from subprocess import check_output
status = check_output(['acpi'], universal_newlines=True)
if not status:
# stands for no battery found
fulltext = "<span color='red'>🔋❌</span>"
percentleft = 100
else:
# if there is more than one battery in one laptop, the percentage left is
# available for each battery separately, although state and remaining
# time for overall block is shown in the status of the first battery
batteries = status.split("\n")
state_batteries=[]
commasplitstatus_batteries=[]
percentleft_batteries=[]
time = ""
for battery in batteries:
if battery!='':
state_batteries.append(battery.split(": ")[1].split(", ")[0])
commasplitstatus = battery.split(", ")
if not time:
time = commasplitstatus[-1].strip()
# check if it matches a time
time = re.match(r"(\d+):(\d+)", time)
if time:
time = ":".join(time.groups())
timeleft = " ({})".format(time)
else:
timeleft = ""
p = int(commasplitstatus[1].rstrip("%\n"))
if p>0:
percentleft_batteries.append(p)
commasplitstatus_batteries.append(commasplitstatus)
state = state_batteries[0]
commasplitstatus = commasplitstatus_batteries[0]
if percentleft_batteries:
percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries))
else:
percentleft = 0
# stands for charging
FA_LIGHTNING = ""
# stands for plugged in
FA_PLUG = "🔌"
# stands for using battery
FA_BATTERY = "🔋"
# stands for unknown status of battery
FA_QUESTION = ""
discharging=True
if state == "Discharging":
fulltext = FA_BATTERY + " "
elif state == "Full":
fulltext = FA_PLUG + " "
timeleft = ""
discharging=False
elif state == "Unknown":
fulltext = FA_BATTERY + FA_QUESTION + " "
timeleft = ""
else:
fulltext = FA_PLUG + FA_LIGHTNING + " "
discharging=False
def color(percent):
if percent < 10:
# exit code 33 will turn background red
return "#FFFFFF"
if percent < 15:
return "#FF3300"
if percent < 20:
return "#FF6600"
if percent < 25:
return "#FF9900"
if percent < 30:
return "#FFCC00"
if percent < 35:
return "#FFFF00"
if percent < 40:
return "#FFFF33"
if percent < 45:
return "#FFFF66"
return "#FFFFFF"
if discharging:
form = '<span color="{}">{}%</span>'
fulltext += form.format(color(percentleft), percentleft)
else:
form = '{}%'
fulltext += form.format(percentleft)
fulltext += timeleft
print(fulltext)
print(fulltext)
if percentleft < 10:
exit(33)
#!/usr/bin/env perl
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
use strict;
use warnings;
use utf8;
use Getopt::Long;
# default values
my $t_warn = 80;
my $t_crit = 90;
my $cpu_usage = -1;
my $decimals = 2;
sub help {
print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit,
"d=i" => \$decimals,
);
# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;
while (<MPSTAT>) {
if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) {
$cpu_usage = 100 - $1; # 100% - %idle
last;
}
}
close(MPSTAT);
$cpu_usage eq -1 and die 'Can\'t find CPU information';
# Print short_text, full_text
printf "%.${decimals}f%%\n", $cpu_usage;
printf "%.${decimals}f%%\n", $cpu_usage;
# Print color, if needed
if ($cpu_usage >= $t_crit) {
print "#FF0000\n";
#exit 33;
} elsif ($cpu_usage >= $t_warn) {
print "#FFFC00\n";
}
exit 0;
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------
# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
IF=$BLOCK_INSTANCE
else
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
#------------------------------------------------------------------------
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${IF} ]] && exit
#------------------------------------------------------------------------
AF=inet6?
LABEL=""
for flag in "$1" "$2"; do
case "$flag" in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
-L)
if [[ "$IF" = "" ]]; then
LABEL="iface "
else
LABEL="$IF: "
fi ;;
esac
done
if [[ "$IF" = "" ]] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
echo "${LABEL}down" # full text
echo "${LABEL}down" # short text
echo \#FF0000 # color
exit
fi
# if no interface is found, use the first device with a global scope
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
case $BLOCK_BUTTON in
3) echo -n "$IPADDR" | xclip -q -se c ;;
esac
#------------------------------------------------------------------------
echo "$LABEL$IPADDR" # full text
echo "$LABEL$IPADDR" # short text
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment