Closed Agent-E11 closed 3 months ago
Possible implementation details using files:
Get number of batteries:
-- Length of this table:
local battery_paths = vim.split(vim.fn.glob("/sys/class/power_supply/BAT*"), "\n")
Get percentage (of the first battery):
local f = io.open(battery_paths[0] .. "/capacity", "r")
if f == nil then
-- file not present
end
-- This is a number from 0 to 100 (or nil if it wasn't a number, which is probably impossible?)
local percentage = f:read("*number")
There is also a file called /sys/class/power_supply/BAT?/status
, which has multiple different possible values. So far I have seen Charging
, Discharging
, Full
, and Unknown
, but I don't know if there are other possible statuses.
Thanks. Some good points. I may look into switching to using /sys/class/power_supply/BAT?/status at some point. Support for the linux kernel is not completely accurate in WSL and acpid does not work but /sys/class/power_supply/BAT?/status also did not work 2 years ago.
In the meantime I am open to PRs.
but /sys/class/power_supply/BAT?/status also did not work 2 years ago
Could you explain this? How did it not work?
Currently in WSL, all of the examples I posted work, so it has likely been fixed unless you have some other cases which I did not come across.
From memory it reported no batteries in WSL
I have tried installing
acpid
on WSL, but it doesn't seem to work. I know there are files in/sys/class/power_supply/
which supply all the data that the plugin needs. Is there a reason why the plugin depends onacpi
instead of using these files? (Someone mentioned in #1 that these files are supplied by the Linux kernel, so they should work for all distributions). I think this is a more sensible default than requiringacpi
as a dependency.