Initial commit
This commit is contained in:
commit
22bc368133
20 changed files with 1145 additions and 0 deletions
84
dot_config/i3/scripts/executable_battery2
Normal file
84
dot_config/i3/scripts/executable_battery2
Normal file
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2016 James Murphy
|
||||
# Licensed under the GPL version 2 only
|
||||
#
|
||||
# A battery indicator blocklet script for i3blocks
|
||||
|
||||
from subprocess import check_output
|
||||
import os
|
||||
import re
|
||||
|
||||
config = dict(os.environ)
|
||||
status = check_output(['acpi'], universal_newlines=True)
|
||||
|
||||
if not status:
|
||||
# stands for no battery found
|
||||
fulltext = "<span font='FontAwesome' color='#fb4934'>\uf00d \uf240</span>".format(color)
|
||||
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=[]
|
||||
for battery in batteries:
|
||||
if battery!='':
|
||||
state_batteries.append(battery.split(": ")[1].split(", ")[0])
|
||||
commasplitstatus = battery.split(", ")
|
||||
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
|
||||
|
||||
def color(percent):
|
||||
if percent < 35:
|
||||
return colors.get("low")
|
||||
if percent < 75 and percent > 35:
|
||||
return colors.get("mid")
|
||||
if percent > 50:
|
||||
return colors.get("high")
|
||||
return "#FFFFFF"
|
||||
|
||||
B_TEMPLATE = "<span font='FontAwesome'>{}</span>"
|
||||
|
||||
B_FULL = B_TEMPLATE.format("\uf240")
|
||||
B_MID = B_TEMPLATE.format("\uf242")
|
||||
|
||||
B_DISCHARING = B_TEMPLATE.format("\uf241")
|
||||
B_CHARGING = B_TEMPLATE.format("\uf1e6")
|
||||
B_DOWN = B_TEMPLATE.format("\uf06a")
|
||||
B_UNKNOWN = B_TEMPLATE.format("\uf128")
|
||||
|
||||
colors = {
|
||||
'low': '#fb4934',
|
||||
'mid': '#fabd2f',
|
||||
'high': '#b8bb26'
|
||||
}
|
||||
|
||||
display = "<span color=\"{}\">{}{}%</span>"
|
||||
battery = ""
|
||||
color = color(percentleft)
|
||||
|
||||
if state == "Discharging":
|
||||
battery = B_DISCHARING + " "
|
||||
elif state == "Full":
|
||||
battery = B_FULL + " "
|
||||
elif state == "Unknown":
|
||||
battery = B_UNKNOWN + " " + B_FULL + " "
|
||||
else:
|
||||
battery = B_CHARGING + " " + B_MID + " "
|
||||
|
||||
display = display.format(color, battery, percentleft)
|
||||
|
||||
print(display)
|
||||
if percentleft < 10:
|
||||
exit(33)
|
Loading…
Add table
Add a link
Reference in a new issue