2020-01-16 18:03:20 +01:00
|
|
|
|
#!/bin/bash
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Récupération des infos de la batterie
|
|
|
|
|
readarray -t batteries <<< $(acpi battery)
|
|
|
|
|
battery=${batteries[${BLOCK_INSTANCE:-0}]}
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Stockage en variables
|
|
|
|
|
percentage=$(echo $battery | grep -o -m1 '[0-9]\{1,3\}%' | tr -d '%')
|
|
|
|
|
status=$(echo $battery | grep -E -o -m1 ': [[:alpha:]]*,' | tr -cd '[:alpha:]')
|
|
|
|
|
remaining=$(echo $battery | grep -E -o -m1 '[0-9]{2}:[0-9]{2}')
|
2018-11-10 05:22:08 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Définition des couleurs
|
|
|
|
|
dis_colors=("#F2777A" "#F2777A" "#F99157" "#F99157" "#FFCC66" "#FFCC66" "#99CC99" "#99CC99")
|
2018-03-06 18:49:41 +01:00
|
|
|
|
charging_color="#66CCCC"
|
|
|
|
|
ac_color="#6699CC"
|
2020-01-16 18:03:20 +01:00
|
|
|
|
full_color="#D3D0C8"
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Création de la barre « graphique »
|
|
|
|
|
percents=$(( percentage / 2 ))
|
|
|
|
|
(( percents > 48 )) && percents=48
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
full_squares=$(( percents / 8 ))
|
|
|
|
|
for t in $(seq 1 $full_squares)
|
|
|
|
|
do
|
|
|
|
|
squares+="█"
|
2018-03-06 18:49:41 +01:00
|
|
|
|
done
|
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
if [[ $(( percents - ( full_squares * 8 ) )) -eq 7 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="█"
|
|
|
|
|
squares+="▉"
|
|
|
|
|
#squares+="▇"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 6 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="▓"
|
|
|
|
|
squares+="▊"
|
|
|
|
|
#squares+="▆"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 5 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="▓"
|
|
|
|
|
squares+="▋"
|
|
|
|
|
#squares+="▅"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 4 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="▒"
|
|
|
|
|
squares+="▌"
|
|
|
|
|
#squares+="▄"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 3 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="▒"
|
|
|
|
|
squares+="▍"
|
|
|
|
|
#squares+="▃"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 2 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="░"
|
|
|
|
|
squares+="▎"
|
|
|
|
|
#squares+="▂"
|
|
|
|
|
elif [[ $(( percents - ( full_squares * 8 ) )) -eq 1 ]]
|
|
|
|
|
then
|
|
|
|
|
#squares+="░"
|
|
|
|
|
squares+="▏"
|
|
|
|
|
#squares+="▁"
|
|
|
|
|
fi
|
2019-01-21 08:16:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Complétion de la barre afin d'avoir une taille fixe
|
|
|
|
|
blanks=$(( 6 - ${#squares} ))
|
|
|
|
|
for t in $(seq 1 $blanks)
|
2018-03-06 18:49:41 +01:00
|
|
|
|
do
|
2020-01-16 18:03:20 +01:00
|
|
|
|
squares+=" "
|
|
|
|
|
done
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Choix de la couleur
|
|
|
|
|
case "${status}" in
|
|
|
|
|
"Charging")
|
|
|
|
|
color="$charging_color"
|
|
|
|
|
;;
|
|
|
|
|
"Full")
|
|
|
|
|
color="$full_color"
|
|
|
|
|
;;
|
|
|
|
|
"AC")
|
|
|
|
|
color="$ac_color"
|
|
|
|
|
;;
|
|
|
|
|
"Discharging"|"Unknown")
|
|
|
|
|
if (( percentage >= 0 && percentage < 10 )); then
|
|
|
|
|
color="${dis_colors[0]}"
|
|
|
|
|
elif (( percentage >= 10 && percentage < 20 )); then
|
|
|
|
|
color="${dis_colors[1]}"
|
|
|
|
|
elif (( percentage >= 20 && percentage < 30 )); then
|
|
|
|
|
color="${dis_colors[2]}"
|
|
|
|
|
elif (( percentage >= 30 && percentage < 40 )); then
|
|
|
|
|
color="${dis_colors[3]}"
|
|
|
|
|
elif (( percentage >= 40 && percentage < 60 )); then
|
|
|
|
|
color="${dis_colors[4]}"
|
|
|
|
|
elif (( percentage >= 60 && percentage < 70 )); then
|
|
|
|
|
color="${dis_colors[5]}"
|
|
|
|
|
elif (( percentage >= 70 && percentage < 80 )); then
|
|
|
|
|
color="${dis_colors[6]}"
|
|
|
|
|
elif (( percentage >= 80 )); then
|
|
|
|
|
color="${dis_colors[7]}"
|
2018-03-06 18:49:41 +01:00
|
|
|
|
fi
|
2020-01-16 18:03:20 +01:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Format détaillé en cas de clic
|
|
|
|
|
if [[ -n "$BLOCK_BUTTON" ]]
|
|
|
|
|
then
|
|
|
|
|
message="<span foreground=\"$color\">${status} ${percentage}%</span> ${remaining}"
|
|
|
|
|
message=${message% }
|
|
|
|
|
else
|
|
|
|
|
message="<span foreground=\"$color\" background=\"#515151\">$squares</span>"
|
|
|
|
|
fi
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|
2020-01-16 18:03:20 +01:00
|
|
|
|
# Affichage
|
|
|
|
|
echo "bat $message"
|
|
|
|
|
echo "bat <span foreground=\"$color\">${percentage}%</span>"
|
2018-03-06 18:49:41 +01:00
|
|
|
|
|