refactor: cleanup scripts

This commit is contained in:
Abhishek Keshri 2024-03-17 04:00:27 +05:30 committed by Abhishek Keshri
parent 15b06d5196
commit d2e517d76a
9 changed files with 60 additions and 160 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@ -10,89 +10,45 @@ linux_acpi() {
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
if [ ! -x "$(which acpi 2>/dev/null)" ]; then
case "$arg" in
status)
cat "$BAT"/status
;;
percent)
cat "$BAT"/capacity
;;
*) ;;
status) cat "$BAT"/status ;;
percent) cat "$BAT"/capacity ;;
esac
else
case "$arg" in
status)
acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' '
;;
percent)
acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% '
;;
*) ;;
status) acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' ' ;;
percent) acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% ' ;;
esac
fi
}
battery_percent() {
# Check OS
case $(uname -s) in
Linux)
percent=$(linux_acpi percent)
[ -n "$percent" ] && echo " $percent"
;;
Darwin)
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%' | sed 's/%//g')
;;
Darwin) echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%' | sed 's/%//g') ;;
FreeBSD)
echo $(apm | sed '8,11d' | grep life | awk '{print $4}')
;;
FreeBSD) echo $(apm | sed '8,11d' | grep life | awk '{print $4}') ;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
# leaving empty - TODO - windows compatability
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*) ;; # TODO - windows compatability
esac
}
battery_status() {
# Check OS
case $(uname -s) in
Linux)
status=$(linux_acpi status)
;;
Darwin)
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ")
;;
FreeBSD)
status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}')
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
# leaving empty - TODO - windows compatibility
;;
*) ;;
Linux) status=$(linux_acpi status) ;;
Darwin) status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ") ;;
FreeBSD) status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}') ;;
CYGWIN* | MINGW32* | MSYS* | MINGW*) ;;
esac
case $status in
discharging | Discharging)
echo ''
;;
high)
echo ''
;;
charging)
echo ''
;;
*)
echo ''
;;
discharging | Discharging) echo '' ;;
high) echo '' ;;
charging) echo '' ;;
*) echo '' ;;
esac
}