#!/bin/bash # mark this file as executable, # then change your sway config (.config/sway/): # # [...] # bar { # [...] # # # When the status_command prints a new line to stdout, swaybar updates. # status_command ~/.config/sway/swaystatus_mark # # [...] # } # [...] while true; do BatteryStatus="$(upower -i /org/freedesktop/UPower/devices/battery_BAT0)" echo "$BatteryStatus" >&2 Perc="$(echo "$BatteryStatus" | grep -i 'percentage' | grep -ioE '\-?[01-9,.]+%')" Watt="$(echo "$BatteryStatus" | grep -i 'energy-rate' | grep -ioE '\-?[01-9,.]+ ?W' | grep -ioE '\-?[01-9]+' | head -n 1)" Remaining="$(echo "$BatteryStatus" | grep -i 'time to empty' | grep -ioE '\-?[01-9,.]+.*')" Time="$(date +'%H:%M:%S | %F')" printf '%s, %sW → %s | %s \n' "$Perc" "$Watt" "$Remaining" "$Time" snooze -H '*' -M '*' -S '/5' || sleep 5 done