mirror of
https://github.com/b-ryan/powerline-shell.git
synced 2026-09-10 07:26:28 -04:00
Merge 5bfc2eb4ec into 4b19aa47f1
This commit is contained in:
commit
0b312f853f
|
|
@ -1,6 +1,7 @@
|
|||
from ..utils import BasicSegment, warn
|
||||
import os
|
||||
|
||||
from sys import platform
|
||||
MACOS = platform == "darwin"
|
||||
|
||||
class Segment(BasicSegment):
|
||||
def add_to_powerline(self):
|
||||
|
|
@ -10,14 +11,32 @@ class Segment(BasicSegment):
|
|||
dir_ = "/sys/class/power_supply/BAT0"
|
||||
elif os.path.exists("/sys/class/power_supply/BAT1"):
|
||||
dir_ = "/sys/class/power_supply/BAT1"
|
||||
elif MACOS:
|
||||
pass
|
||||
else:
|
||||
warn("battery directory could not be found")
|
||||
return
|
||||
if MACOS:
|
||||
# This way the non-macos people don't have to pay for the imports
|
||||
from subprocess import check_output
|
||||
import re
|
||||
source = check_output(["pmset", "-g", "batt"]).strip().decode()
|
||||
# capacity
|
||||
cap = int(re.findall(r"[0-9]{1,3}%", source)[0][:-1])
|
||||
status_source = source[source.find(";") + 2: source.rfind(";")]
|
||||
|
||||
with open(os.path.join(dir_, "capacity")) as f:
|
||||
cap = int(f.read().strip())
|
||||
with open(os.path.join(dir_, "status")) as f:
|
||||
status = f.read().strip()
|
||||
if status_source == "charged":
|
||||
status = "Full"
|
||||
elif status_source == "charging":
|
||||
status = "Charging"
|
||||
else:
|
||||
status = "Discharging"
|
||||
|
||||
else:
|
||||
with open(os.path.join(dir_, "capacity")) as f:
|
||||
cap = int(f.read().strip())
|
||||
with open(os.path.join(dir_, "status")) as f:
|
||||
status = f.read().strip()
|
||||
if status == "Full":
|
||||
if self.powerline.segment_conf("battery", "always_show_percentage", False):
|
||||
pwr_fmt = u" {cap:d}% \U0001F50C "
|
||||
|
|
|
|||
Loading…
Reference in a new issue