Add a custom battery script for FreeBSD.
This commit is contained in:
parent
22ebc631fc
commit
7b625d19a5
@ -50,8 +50,9 @@
|
|||||||
#battery,
|
#battery,
|
||||||
#clock,
|
#clock,
|
||||||
#cpu,
|
#cpu,
|
||||||
#custom-keyboard-layout,
|
#custom-battery,
|
||||||
#custom-clock,
|
#custom-clock,
|
||||||
|
#idle_inhibitor,
|
||||||
#memory,
|
#memory,
|
||||||
#mode,
|
#mode,
|
||||||
#network,
|
#network,
|
||||||
@ -60,6 +61,7 @@
|
|||||||
#tray {
|
#tray {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
|
border: 1px solid white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
50
ansible/roles/sway/files/waybar_battery
Normal file
50
ansible/roles/sway/files/waybar_battery
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Read battery status in FreeBSD
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
# TODO: Which is better, apm or reading sysctls from hw.acpi.battery ?
|
||||||
|
|
||||||
|
SLEEP_INTERVAL=${SLEEP_INTERVAL:-30}
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
battery_percentage=$(apm -l)
|
||||||
|
battery_status=$(apm -b)
|
||||||
|
seconds_remaining=$(apm -t)
|
||||||
|
|
||||||
|
if [ $battery_status -eq 3 ]; 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
|
||||||
|
|
||||||
|
jq --unbuffered --compact-output <<EOF
|
||||||
|
{
|
||||||
|
"text":"${battery_percentage}% ${battery_icon}",
|
||||||
|
"tooltip":"${time_remaining}",
|
||||||
|
"percentage":${battery_percentage}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
sleep $SLEEP_INTERVAL
|
||||||
|
done
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
// "height": 10, // Waybar height (to be removed for auto height)
|
// "height": 10, // Waybar height (to be removed for auto height)
|
||||||
"modules-left": ["sway/workspaces", "sway/mode"],
|
"modules-left": ["sway/workspaces", "sway/mode"],
|
||||||
"modules-right": ["idle_inhibitor", "custom/clock", "tray"],
|
"modules-right": ["custom/battery", "idle_inhibitor", "custom/clock", "tray"],
|
||||||
"sway/workspaces": {
|
"sway/workspaces": {
|
||||||
"disable-scroll": true,
|
"disable-scroll": true
|
||||||
},
|
},
|
||||||
"sway/mode": {
|
"sway/mode": {
|
||||||
"format": "<span style=\"italic\">{}</span>"
|
"format": "<span style=\"italic\">{}</span>"
|
||||||
@ -23,5 +23,10 @@
|
|||||||
"exec": "waybar_custom_clock",
|
"exec": "waybar_custom_clock",
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"restart-interval": 30
|
"restart-interval": 30
|
||||||
|
},
|
||||||
|
"custom/battery": {
|
||||||
|
"exec": "waybar_custom_battery",
|
||||||
|
"return-type": "json",
|
||||||
|
"restart-interval": 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
loop:
|
loop:
|
||||||
- src: waybar_custom_clock.py
|
- src: waybar_custom_clock.py
|
||||||
dest: /usr/local/bin/waybar_custom_clock
|
dest: /usr/local/bin/waybar_custom_clock
|
||||||
|
- src: waybar_battery
|
||||||
|
dest: /usr/local/bin/waybar_custom_battery
|
||||||
|
|
||||||
- import_tasks: tasks/freebsd.yaml
|
- import_tasks: tasks/freebsd.yaml
|
||||||
when: 'os_flavor == "freebsd"'
|
when: 'os_flavor == "freebsd"'
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
- wtype # for rofimoji to be able to insert characters
|
- wtype # for rofimoji to be able to insert characters
|
||||||
- dbus # for desktop notifications
|
- dbus # for desktop notifications
|
||||||
- lumina-fm
|
- lumina-fm
|
||||||
|
- jq
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Install service configuration
|
- name: Install service configuration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user