Add a linux waybar battery module.
This commit is contained in:
parent
7c37f6d133
commit
a6409f4730
@ -5,7 +5,7 @@ default-cache-ttl 600
|
||||
max-cache-ttl 7200
|
||||
display :0
|
||||
{% if os_flavor == "linux" %}
|
||||
pinentry-program /usr/bin/pinentry-qt5
|
||||
pinentry-program /usr/bin/pinentry-qt
|
||||
{% elif os_flavor == "freebsd" %}
|
||||
pinentry-program /usr/local/bin/pinentry-qt5
|
||||
{% endif %}
|
||||
|
62
ansible/roles/sway/files/waybar_battery_linux
Normal file
62
ansible/roles/sway/files/waybar_battery_linux
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Read battery status in FreeBSD
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
SLEEP_INTERVAL=${SLEEP_INTERVAL:-30}
|
||||
|
||||
batteries=$(find /sys/class/power_supply -name 'BAT*')
|
||||
|
||||
while true; do
|
||||
text=""
|
||||
tooltip=""
|
||||
percentage=""
|
||||
while read bat; do
|
||||
battery_now=$(cat "$bat/charge_now")
|
||||
battery_capacity=$(cat "$bat/charge_full")
|
||||
battery_percentage=$(( battery_now * 100 / battery_capacity ))
|
||||
battery_status=$(cat "$bat/status")
|
||||
seconds_remaining="-1"
|
||||
|
||||
if [ $battery_status = "Charging" ]; then
|
||||
if [ $battery_percentage -eq 100 ]; then
|
||||
battery_icon=""
|
||||
else
|
||||
battery_icon=""
|
||||
fi
|
||||
elif [ $battery_percentage -le 20 ]; then
|
||||
battery_icon=""
|
||||
elif [ $battery_percentage -le 40 ]; then
|
||||
battery_icon=""
|
||||
elif [ $battery_percentage -le 60 ]; then
|
||||
battery_icon=""
|
||||
elif [ $battery_percentage -le 80 ]; then
|
||||
battery_icon=""
|
||||
elif [ $battery_percentage -lt 100 ]; then
|
||||
battery_icon=""
|
||||
else
|
||||
battery_icon=""
|
||||
fi
|
||||
if [ $seconds_remaining -eq -1 ]; then
|
||||
time_remaining="unknown time remaining."
|
||||
else
|
||||
time_remaining=$(printf '%dh:%dm:%ds\n' $((seconds_remaining/3600)) $((seconds_remaining%3600/60)) $((seconds_remaining%60)) )
|
||||
fi
|
||||
|
||||
text="$text${battery_percentage}% ${battery_icon}"
|
||||
tooltip="$tooltip${time_remaining}"
|
||||
percentage="$percentage${battery_percentage}"
|
||||
done<<<"$batteries"
|
||||
|
||||
|
||||
jq --unbuffered --compact-output <<EOF
|
||||
{
|
||||
"text":"$text",
|
||||
"tooltip":"$tooltip",
|
||||
"percentage":$percentage
|
||||
}
|
||||
EOF
|
||||
sleep $SLEEP_INTERVAL
|
||||
done
|
@ -8,8 +8,6 @@
|
||||
loop:
|
||||
- src: waybar_custom_clock.py
|
||||
dest: /usr/local/bin/waybar_custom_clock
|
||||
- src: waybar_battery
|
||||
dest: /usr/local/bin/waybar_custom_battery
|
||||
|
||||
- import_tasks: tasks/freebsd.yaml
|
||||
when: 'os_flavor == "freebsd"'
|
||||
|
@ -47,3 +47,5 @@
|
||||
loop:
|
||||
- src: launch_sway_freebsd.bash
|
||||
dest: /usr/local/bin/launch_sway
|
||||
- src: waybar_battery_freebsd
|
||||
dest: /usr/local/bin/waybar_custom_battery
|
||||
|
@ -1,10 +1,3 @@
|
||||
# - name: Install packages
|
||||
# pacman:
|
||||
# name:
|
||||
# - foo
|
||||
# state: present
|
||||
# update_cache: true
|
||||
|
||||
- name: Install scripts
|
||||
copy:
|
||||
src: "files/{{ item.src }}"
|
||||
@ -15,3 +8,5 @@
|
||||
loop:
|
||||
- src: launch_sway_linux.bash
|
||||
dest: /usr/local/bin/launch_sway
|
||||
- src: waybar_battery_linux
|
||||
dest: /usr/local/bin/waybar_custom_battery
|
||||
|
Loading…
Reference in New Issue
Block a user