From c0a2cce420c12bac04c0b04698e550edde91cf24 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Mon, 16 Jul 2018 19:16:47 -0400 Subject: [PATCH] separate battery script with colors --- .config/i3blocks/config | 4 ++-- .scripts/i3battery | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.config/i3blocks/config b/.config/i3blocks/config index b1c778d..3fc44a0 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -47,11 +47,11 @@ interval=10 [wifi] label=📶 -#instance=wlp3s0 +instance=wlp2s0 interval=10 [battery] -command=echo $(cat /sys/class/power_supply/BAT0/status | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/❓/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g") $(cat /sys/class/power_supply/BAT0/capacity | sed -e 's/$/%/') +command=i3battery interval=5 [time] diff --git a/.scripts/i3battery b/.scripts/i3battery index a632b9b..7b613a0 100755 --- a/.scripts/i3battery +++ b/.scripts/i3battery @@ -1,2 +1,24 @@ -#!/bin/sh -#acpi | cut -d " " -f3-5 | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g" +#!/bin/bash +NUM=$(cat /sys/class/power_supply/BAT0/capacity) +STATE=$(cat /sys/class/power_supply/BAT0/status) + +colorget() { +if [[ $NUM -ge 80 ]]; then + color="#00FF00" +elif [[ $NUM -ge 60 ]]; then + color="#FF0000" +elif [[ $NUM -ge 40 ]]; then + color="#FFF600" +elif [[ $NUM -ge 20 ]]; then + color="#FFAE00" +else + color="#FF0000" +fi ;} + +if [[ $STATE == "Charging" ]]; then + color="#ffffff" +else + colorget +fi + +echo "$(echo $STATE | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/❓/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g") $(echo $NUM | sed -e 's/$/%/')"