mirror of
https://github.com/eRgo35/dwm.git
synced 2025-12-15 05:16:11 +01:00
fix: bar changes
This commit is contained in:
53
bar.sh
53
bar.sh
@@ -156,22 +156,55 @@ get_brightness() {
|
||||
|
||||
# Function to get weighted average battery level
|
||||
get_battery_level() {
|
||||
# Get battery levels (adjust paths if needed)
|
||||
battery0_level=$(cat /sys/class/power_supply/BAT0/capacity)
|
||||
battery1_level=$(cat /sys/class/power_supply/BAT1/capacity)
|
||||
BAT_PATHS=(/sys/class/power_supply/BAT*)
|
||||
|
||||
battery0_energy_full=$(cat /sys/class/power_supply/BAT0/energy_full)
|
||||
battery1_energy_full=$(cat /sys/class/power_supply/BAT1/energy_full)
|
||||
total_now=0
|
||||
total_full=0
|
||||
|
||||
for BAT in "${BAT_PATHS[@]}"; do
|
||||
if [[ -f "$BAT/energy_now" && -f "$BAT/energy_full" ]]; then
|
||||
now=$(<"$BAT/energy_now")
|
||||
full=$(<"$BAT/energy_full")
|
||||
elif [[ -f "$BAT/charge_now" && -f "$BAT/charge_full" ]]; then
|
||||
now=$(<"$BAT/charge_now")
|
||||
full=$(<"$BAT/charge_full")
|
||||
else
|
||||
continue
|
||||
fi
|
||||
|
||||
total_now=$((total_now + now))
|
||||
total_full=$((total_full + full))
|
||||
done
|
||||
|
||||
if [[ $total_full -eq 0 ]]; then
|
||||
percent=0
|
||||
else
|
||||
percent=$((100 * total_now / total_full))
|
||||
fi
|
||||
|
||||
if (( percent < 15 )); then
|
||||
echo "^c$TEXT^^b$LOVE^BAT: $percent%^b$BASE^"
|
||||
else
|
||||
echo "^c$LOVE^BAT: $percent%"
|
||||
fi
|
||||
# Get battery levels (adjust paths if needed)
|
||||
# battery0_level=$(cat /sys/class/power_supply/BAT0/capacity)
|
||||
# battery1_level=$(cat /sys/class/power_supply/BAT1/capacity)
|
||||
|
||||
# battery0_energy_full=$(cat /sys/class/power_supply/BAT0/energy_full)
|
||||
# battery1_energy_full=$(cat /sys/class/power_supply/BAT1/energy_full)
|
||||
|
||||
# Calculate weights based on energy capacity
|
||||
weight0=$(awk "BEGIN {printf \"%.2f\", $battery0_energy_full / ($battery0_energy_full + $battery1_energy_full)}")
|
||||
weight1=$(awk "BEGIN {printf \"%.2f\", $battery1_energy_full / ($battery0_energy_full + $battery1_energy_full)}")
|
||||
# weight0=$(awk "BEGIN {printf \"%.2f\", $battery0_energy_full / ($battery0_energy_full + $battery1_energy_full)}")
|
||||
# weight1=$(awk "BEGIN {printf \"%.2f\", $battery1_energy_full / ($battery0_energy_full + $battery1_energy_full)}")
|
||||
|
||||
# Calculate weighted average
|
||||
weighted_avg=$(awk "BEGIN {printf \"%.0f%%\", ($battery0_level * $weight0 + $battery1_level * $weight1)}")
|
||||
|
||||
# weighted_avg=$(awk "BEGIN {printf \"%.0f%%\", ($battery0_level * $weight0 + $battery1_level * $weight1)}")
|
||||
# battery0_level=$(cat /sys/class/power_supply/BAT0/capacity)
|
||||
# echo "^c$LOVE^BAT: $battery0_level%"
|
||||
|
||||
# Output the result with color
|
||||
echo "^c$LOVE^BAT: $weighted_avg"
|
||||
# echo "^c$LOVE^BAT: $weighted_avg"
|
||||
}
|
||||
|
||||
# Function to get date and time in American 12-hour format
|
||||
|
||||
Reference in New Issue
Block a user