From aaba65007866de34d235bb7425cd3999aaba42e7 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Wed, 16 Feb 2022 19:47:55 +0100 Subject: [PATCH] Refactor battery, handle when not a laptop so no battery --- dotfiles/i3/scripts/battery | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/dotfiles/i3/scripts/battery b/dotfiles/i3/scripts/battery index 6583423..cba88ca 100755 --- a/dotfiles/i3/scripts/battery +++ b/dotfiles/i3/scripts/battery @@ -1,16 +1,20 @@ #!/bin/bash icon="" -percent="$(upower -d | grep 'percentage' | awk '{print $2}' | head -n 1)" -remaining="$(upower -d | grep 'time to empty' | awk -F: '{print $2}' | awk '{print $1,$2}' | head -n 1)" +battery="$(upower -d | awk '/on-battery/ {print $2}')" +percent="$(upower -d | awk '/percentage/ {print $2}' | head -n 1)" +remaining="$(upower -d | awk -F: '/time to empty/ {print $2}' | awk '{print $1,$2}' | head -n 1)" -if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then - notify-send "CHARGE BATTERY" - for file in /dev/pts/*; do - if [ "$(ls -l "$file" | awk '{print $5}')" = '136,' ]; then - echo "CHARGE BATTERY" >> "$file" - fi - done +if [ "$battery" = 'yes' ]; then + if [ -n "$remaining" ] && [ "$(echo "$percent" | awk -F% '{print $1}')" -lt "$THRESHOLD" ]; then + notify-send "CHARGE BATTERY" + for file in /dev/pts/*; do + if [ "$(ls -l "$file" | awk '{print $5}')" = '136,' ]; then + echo "CHARGE BATTERY" >> "$file" + fi + done + fi + echo "${icon} ${percent} (${remaining})" +else + echo "" fi - -echo "${icon} ${percent} (${remaining})"