feat: enhance battery segment

This commit is contained in:
Abhishek Keshri 2023-11-15 08:17:52 +05:30
parent 416d0a1151
commit f4c81ed798
No known key found for this signature in database
GPG key ID: 62BD6AA2E913B3D3

View file

@ -97,27 +97,37 @@ battery_status() {
echo '' echo ''
;; ;;
esac esac
### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure }
# if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then
# echo '' battery_label() {
# # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support bat_perc=$1
# # echo 'AC'
# else if [ "$bat_perc" -gt 90 ]; then
# echo 'AC' echo " "
# fi elif [ "$bat_perc" -gt 75 ]; then
echo " "
elif [ "$bat_perc" -gt 50 ]; then
echo " "
elif [ "$bat_perc" -gt 25 ]; then
echo " "
elif [ "$bat_perc" -gt 10 ]; then
echo " "
else
echo ""
fi
} }
main() { main() {
bat_label=$(get_tmux_option "@tmux2k-battery-label" "")
bat_stat=$(battery_status) bat_stat=$(battery_status)
bat_perc=$(battery_percent) bat_perc=$(battery_percent)
bat_label=$(get_tmux_option "@tmux2k-battery-label" "$(battery_label "$bat_perc")")
if [ -z "$bat_stat" ]; then # Test if status is empty or not if [ -z "$bat_stat" ]; then # Test if status is empty or not
echo "$bat_label$bat_perc" echo "$bat_label $bat_perc%"
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
echo "$bat_label $bat_stat" echo "$bat_stat $bat_label"
else else
echo "$bat_label $bat_stat$bat_perc" echo "$bat_stat $bat_label $bat_perc%"
fi fi
} }