From 97eb64c307245dbeaaee72b31d4d7a04c4914436 Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Sun, 23 Jun 2019 17:41:09 -0400 Subject: [PATCH] fish: add battery function --- fish/functions/battery.fish | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 fish/functions/battery.fish diff --git a/fish/functions/battery.fish b/fish/functions/battery.fish new file mode 100644 index 0000000..e443992 --- /dev/null +++ b/fish/functions/battery.fish @@ -0,0 +1,15 @@ +function battery + # Only works on Mac + if test (uname -s) != Darwin + echo "Unsupported OS: "(uname -s) + return 1 + end + + set --local battery_status (pmset -g batt | string split0) + set --local battery_charge (echo $battery_status | rg --only-matching "\d+%") + set --local power_source (echo $battery_status | rg --only-matching "[A-Za-z]+\sPower") + + set_color green + echo "⚡️ Running on $power_source with $battery_charge charge" + set_color normal +end