From d40abb39b2c1f8aa71b571bbbaa1e0c21b83d156 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Thu, 9 Apr 2020 15:08:28 +0000 Subject: [PATCH] Add battery details script --- .bin/check-battery-level | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 .bin/check-battery-level diff --git a/.bin/check-battery-level b/.bin/check-battery-level new file mode 100755 index 0000000..334e2be --- /dev/null +++ b/.bin/check-battery-level @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +capacityStatus=$(cat /sys/class/power_supply/BAT0/capacity) +chargingStatus=$(cat /sys/class/power_supply/AC/online) + +if [ "$chargingStatus" == "1" ]; then + printf "Battery is ${GREEN}charging${NC}.\n" +elif [ "$chargingStatus" == "0" ]; then + printf "Battery is ${RED}discharging${NC}.\n" +fi + +printf "$capacityStatus%% \n"