Created
January 18, 2017 20:03
-
-
Save Juma7C9/1ff02afd2f5003a4131341dec5ed60c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# upower-ksysguardd.sh - Script to poll upower tool with a ksysguardd | |
# compatible interface. Useful with kde/plasma's ksysguard system monitor. | |
# To use it, launch ksysguard, then File -> Connect Host, and choose | |
# "Custom command" (see https://techbase.kde.org/Development/Tutorials/Sensors). | |
# | |
# Copyright (C) 2017 Juma7C9 | |
# | |
# 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, write to the Free Software Foundation, | |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
export LANG=C | |
parse() { | |
case "$1" in | |
monitors) | |
printf "energy\tfloat\n" | |
printf "energy-empty\tfloat\n" | |
printf "energy-full\tfloat\n" | |
printf "energy-full-design\tfloat\n" | |
printf "energy-rate\tfloat\n" | |
printf "voltage\tfloat\n" | |
printf "percentage\tinteger\n" | |
printf "capacity\tfloat\n" | |
;; | |
*\?) | |
case "${1%\?}" in | |
energy) printf "Current charge\t0\t0\tWh\n" ;; | |
energy-empty) printf "Empty charge\t0\t0\tWh\n" ;; | |
energy-full) printf "Full charge\t0\t0\tWh\n" ;; | |
energy-full-design) printf "Design full charge\t0\t0\tWh\n" ;; | |
energy-rate) printf "Current power consumption\t0\t0\tW\n" ;; | |
voltage) printf "Current voltage\t0\t0\tV\n" ;; | |
percentage) printf "Current percentage\t0\t100\t%%\n" ;; | |
capacity) printf "Battery capacity\t0\t100\t%%\n" ;; | |
*) printf "UNKNOWN COMMAND\n" ;; | |
esac | |
;; | |
*) | |
print_value "$1" | |
;; | |
esac | |
} | |
print_value() { | |
upower -i $(upower -e | grep -i bat) | grep "$1": | awk -F' ' '{print $2}' | sed -e 's/%//' | |
} | |
printf "ksysguardd 1.2.0\n" | |
while true | |
do | |
printf "ksysguardd> " | |
read input | |
parse $input | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment