Skip to content

Instantly share code, notes, and snippets.

@bjornpagen
Created November 7, 2025 16:37
Show Gist options
  • Select an option

  • Save bjornpagen/dd1a3a0c8b211c979f10cdffe8ad4e97 to your computer and use it in GitHub Desktop.

Select an option

Save bjornpagen/dd1a3a0c8b211c979f10cdffe8ad4e97 to your computer and use it in GitHub Desktop.
Get battery on Asahi Linux
#!/usr/bin/env lua
local function read_file(path)
local file = io.open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end
local path = "/sys/class/power_supply/macsmc-battery/"
local charge_now = read_file(path .. "charge_now")
local charge_full = read_file(path .. "charge_full")
local percent_left = string.format("%.1f", charge_now/charge_full * 100)
print(percent_left .. "%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment