summaryrefslogtreecommitdiff
path: root/.config/sketchybar/items/widgets/func_utils.lua
blob: b60176df5b9dd7806251b4cd6a48b4dda4af8d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function os.capture(cmd, raw)
	local file = assert(io.popen(cmd, "r"))
	local output = assert(file:read("*a"))
	file:close()

	if raw then
		return output
	end

	output = string.gsub(output, "^%s+", "")
	output = string.gsub(output, "%s+$", "")
	output = string.gsub(output, "[\n\r]+", "")

	return output
end

-- testing battery info here... works
Batt_info = os.capture("pmset -g batt", false)
if Batt_info:find("AC Power") then
	print("Found AC Power in the string.")
else
	local found, _, charge = Batt_info:find("(%d+)%%")
	print("found: " .. found)
	print("_: " .. _)
	print("charge: " .. charge)
end