mirror of
https://git.adityakumar.xyz/dwmbar.git
synced 2024-11-09 22:19:45 +00:00
Merge pull request #4 from thytom/battery-module-fix
Battery module fix
This commit is contained in:
commit
2b024b483f
2 changed files with 38 additions and 39 deletions
12
bar.sh
12
bar.sh
|
@ -15,7 +15,6 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
MODULES_DIR="/usr/share/dwmbar/modules/"
|
MODULES_DIR="/usr/share/dwmbar/modules/"
|
||||||
|
|
||||||
OUTPUT_CACHE="/home/$USER/.config/dwmbar/.cache/"
|
OUTPUT_CACHE="/home/$USER/.config/dwmbar/.cache/"
|
||||||
|
@ -41,8 +40,8 @@ get_bar()
|
||||||
{
|
{
|
||||||
for module in $MODULES; do
|
for module in $MODULES; do
|
||||||
if [[ $INTERNET -eq 0 ]] || [[ $ONLINE_MODULES != *"$module"* ]];then
|
if [[ $INTERNET -eq 0 ]] || [[ $ONLINE_MODULES != *"$module"* ]];then
|
||||||
module_out=$(cat $OUTPUT_CACHE$module | sed 's/\.$//g')
|
module_out="$(cat $OUTPUT_CACHE$module | sed 's/\.$//g')"
|
||||||
bar=$bar$module_out
|
bar="$bar$module_out"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Uncomment to remove last separator
|
# Uncomment to remove last separator
|
||||||
|
@ -60,15 +59,16 @@ run_module()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ ! "$out" = "" ]] && [[ ! "$module" = "NULL" ]] && out="$out$SEPARATOR."
|
[[ ! "$out" = "" ]] && [[ ! "$module" = "NULL" ]] && out="$out$SEPARATOR."
|
||||||
echo $out > "$OUTPUT_CACHE$module"
|
echo "$out" > "$OUTPUT_CACHE$module"
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
get_internet
|
get_internet
|
||||||
for module in $MODULES; do
|
for module in $MODULES; do
|
||||||
if [[ $INTERNET -eq 0 ]]; then
|
pgrep $module &> /dev/null
|
||||||
run_module $module
|
if [[ $INTERNET -eq 0 ]] && [[ $? -eq 1 ]]; then
|
||||||
|
run_module $module &
|
||||||
else
|
else
|
||||||
[[ $ONLINE_MODULES != *"$module"* ]] && run_module $module
|
[[ $ONLINE_MODULES != *"$module"* ]] && run_module $module
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,43 +2,42 @@
|
||||||
|
|
||||||
# Prints out battery percentage
|
# Prints out battery percentage
|
||||||
|
|
||||||
CHARGING_ICON=''
|
CHARGING_ICON=' '
|
||||||
WARNING_ICON=''
|
WARNING_ICON=' '
|
||||||
BATTERY_FULL_ICON=''
|
BATTERY_FULL_ICON=' '
|
||||||
BATTERY_2_ICON=''
|
BATTERY_2_ICON=' '
|
||||||
BATTERY_3_ICON=''
|
BATTERY_3_ICON=' '
|
||||||
BATTERY_4_ICON=''
|
BATTERY_4_ICON=' '
|
||||||
|
|
||||||
|
FULL_AT=98
|
||||||
|
|
||||||
|
BAT_ICON=""
|
||||||
|
ICON=""
|
||||||
|
|
||||||
get_battery()
|
get_battery()
|
||||||
{
|
{
|
||||||
if [ -d /sys/class/power_supply/BAT? ]; then
|
# The vast majority of people only use one battery.
|
||||||
ac_adapter=$(cat /sys/class/power_supply/BAT?/status)
|
|
||||||
if [ "$ac_adapter" == "Charging" ]; then
|
if [ -d /sys/class/power_supply/BAT0 ]; then
|
||||||
echo "$CHARGING_ICON"
|
capacity=$(cat /sys/class/power_supply/BAT0/capacity)
|
||||||
|
charging=$(cat /sys/class/power_supply/BAT0/status)
|
||||||
|
if [[ "$charging" == "Charging" ]]; then
|
||||||
|
ICON="$CHARGING_ICON"
|
||||||
|
elif [[ $capacity -le 25 ]]; then
|
||||||
|
ICON="$WARNING_ICON"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Will show all batteries with approximate icon for remaining power.
|
if [[ $capacity -ge $FULL_AT ]]; then
|
||||||
for x in /sys/class/power_supply/BAT?/capacity;
|
BAT_ICON=$BATTERY_FULL_ICON
|
||||||
do
|
elif [[ $capacity -le 25 ]]; then
|
||||||
case "$(cat $x)" in
|
BAT_ICON=$BATTERY_4_ICON
|
||||||
100) echo "$BATTERY_FULL_ICON" ;;
|
elif [[ $capacity -le 50 ]]; then
|
||||||
9[0-9]) echo "$BATTERY_FULL_ICON $(cat $x)%" ;;
|
BAT_ICON=$BATTERY_3_ICON
|
||||||
8[0-9]|7[0-9]) echo "$BATTERY_2_ICON $(cat $x)%" ;;
|
elif [[ $capacity -le $FULL_AT ]]; then
|
||||||
6[0-9]|5[0-9]) echo "$BATTERY_3_ICON $(cat $x)%" ;;
|
BAT_ICON=$BATTERY_2_ICON
|
||||||
4[0-9]|3[0-9]) echo "$BATTERY_4_ICON $(cat $x)%" ;;
|
|
||||||
2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then
|
|
||||||
echo "$BATTERY_4_ICON $(cat $x)%"
|
|
||||||
else
|
|
||||||
echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
|
|
||||||
fi ;;
|
|
||||||
[0-9]) if [ "$ac_adapter" == "Charging" ]; then
|
|
||||||
echo "$BATTERY_4_ICON $(cat $x)%"
|
|
||||||
else
|
|
||||||
echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
|
|
||||||
fi ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
echo "$ICON $BAT_ICON $capacity%"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_battery
|
get_battery
|
||||||
|
|
Loading…
Reference in a new issue