From 6480ee5b9e05a763eef929250bf14acaa8631202 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 20 Apr 2019 19:30:14 +0200 Subject: pkgs/profpatsch/display-infos: add sfttime and AC charger --- pkgs/profpatsch/default.nix | 2 +- pkgs/profpatsch/display-infos/default.nix | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'pkgs') diff --git a/pkgs/profpatsch/default.nix b/pkgs/profpatsch/default.nix index 962f6c39..347d1679 100644 --- a/pkgs/profpatsch/default.nix +++ b/pkgs/profpatsch/default.nix @@ -60,7 +60,7 @@ in rec { json2json json2string; backlight = callPackage ./backlight { inherit (pkgs.xorg) xbacklight; }; - display-infos = callPackage ./display-infos {}; + display-infos = callPackage ./display-infos { inherit sfttime; }; git-commit-index = callPackage ./git-commit-index { inherit script runCommandLocal; }; nix-http-serve = callPackage ./nix-http-serve {}; nman = callPackage ./nman {}; diff --git a/pkgs/profpatsch/display-infos/default.nix b/pkgs/profpatsch/display-infos/default.nix index d213241c..9dc510cd 100644 --- a/pkgs/profpatsch/display-infos/default.nix +++ b/pkgs/profpatsch/display-infos/default.nix @@ -1,8 +1,8 @@ -{ lib, runCommand, python3, libnotify }: +{ lib, runCommand, writeText, python3, libnotify, sfttime }: let name = "display-infos-0.1.0"; - script = builtins.toFile (name + "-script") '' + script = writeText (name + "-script") '' #!@python3@ import sys @@ -11,19 +11,22 @@ let import os.path as path import statistics as st + def readint(fn): + with open(fn, 'r') as f: + return int(f.read()) + full = 0 now = 0 for bat in glob.iglob("/sys/class/power_supply/BAT*"): - def readint(fn): - with open(fn, 'r') as f: - return int(f.read()) full += readint(path.join(bat, "energy_full")) now += readint(path.join(bat, "energy_now" )) bat = round( now/full, 2 ) + ac = "🗲" if readint("/sys/class/power_supply/AC/online") else "" date = sub.run(["date", "+%d.%m. %a %T"], stdout=sub.PIPE).stdout.strip().decode() - notify = "BAT: {}% | {}".format(int(bat*100), date) + sfttime = sub.run(["${sfttime}/bin/sfttime"], stdout=sub.PIPE).stdout.strip().decode() + notify = "BAT: {}% {} | {} | {}".format(int(bat*100), ac, date, sfttime) sub.run(["@notify-send@", notify]) ''; -- cgit 1.4.1