diff options
author | Michaël Ball <git@michaelball.name> | 2021-02-21 11:47:16 +0000 |
---|---|---|
committer | Michaël Ball <git@michaelball.name> | 2021-02-21 11:47:16 +0000 |
commit | 3de82782746019f605456d57226815eb9aac8369 (patch) | |
tree | 33e1c5e5be3b9b40484fcf78ba774e1d6c7a5ee5 /battery.sh |
Initial commit
Diffstat (limited to 'battery.sh')
-rwxr-xr-x | battery.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/battery.sh b/battery.sh new file mode 100755 index 0000000..78fb773 --- /dev/null +++ b/battery.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +i3status -c $HOME/.config/i3blocks/i3status.conf | while IFS= read -r line; do + PARTS=($line) + + CHARGE="${PARTS[1]}" + CHARGE="${CHARGE%\%*}" + [[ "${CHARGE}" -gt 100 ]] && { + CHARGE="100" + } + + STATE="" + [[ "${PARTS[0]}" = "BAT" ]] && { + STATE="${PARTS[2]}" + [[ -n "${STATE}" ]] && { + STATE="${STATE:0:-3}" + STATE=" (${STATE})" + } + } + + LEVEL=$(( (CHARGE - 1) / 20 )) + ICON="f$(( 244 - LEVEL ))" + + echo -e "\u${ICON} ${CHARGE}%${STATE} " + + [[ "${LEVEL}" = "0" ]] && { + [[ -z "${STATE}" ]] || i3-msg "fullscreen disable" >/dev/null + } +done |