More luarocks jank. Three spaces? ew.
This commit is contained in:
parent
70537a8138
commit
37b616165d
110
flowerfetch.lua
110
flowerfetch.lua
|
@ -10,46 +10,46 @@ print("\27[H\27[2J\27[3J")
|
|||
-- Print out flower from text file
|
||||
local flower = io.open(lua_dir .. "flower.txt", "r")
|
||||
if (flower ~= nil) then
|
||||
print(flower:read("*a"))
|
||||
flower:close()
|
||||
print(flower:read("*a"))
|
||||
flower:close()
|
||||
else
|
||||
print("Error: Missing ASCII flower")
|
||||
os.exit(-1)
|
||||
print("Error: Missing ASCII flower")
|
||||
os.exit(-1)
|
||||
end
|
||||
|
||||
local get_file = function(location, permissions, split_str)
|
||||
local table = {}
|
||||
local got_file = io.open(location, permissions)
|
||||
if (got_file ~= nil) then
|
||||
for line in got_file:lines() do
|
||||
for line_id, line_val in line:gmatch(split_str) do
|
||||
table[line_id] = line_val
|
||||
local table = {}
|
||||
local got_file = io.open(location, permissions)
|
||||
if (got_file ~= nil) then
|
||||
for line in got_file:lines() do
|
||||
for line_id, line_val in line:gmatch(split_str) do
|
||||
table[line_id] = line_val
|
||||
end
|
||||
end
|
||||
end
|
||||
got_file:close()
|
||||
end
|
||||
return table
|
||||
got_file:close()
|
||||
end
|
||||
return table
|
||||
end
|
||||
|
||||
local get_line = function(location)
|
||||
local item = io.open(location, 'r')
|
||||
if (item ~= nil) then
|
||||
local str = item:read('*l')
|
||||
item:close()
|
||||
return str
|
||||
else
|
||||
return ""
|
||||
end
|
||||
local item = io.open(location, 'r')
|
||||
if (item ~= nil) then
|
||||
local str = item:read('*l')
|
||||
item:close()
|
||||
return str
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
-- Get battery stuff
|
||||
local battery = ""
|
||||
local batteries = ""
|
||||
for filename in lfs.dir("/sys/class/power_supply") do
|
||||
if filename ~= "." and filename ~= ".." and filename ~= "AC" then
|
||||
battery = get_line("/sys/class/power_supply/" .. filename .. "/capacity")
|
||||
batteries = string.format("[ %s %s%% ] ", filename, battery) .. batteries
|
||||
end
|
||||
if filename ~= "." and filename ~= ".." and filename ~= "AC" then
|
||||
battery = get_line("/sys/class/power_supply/" .. filename .. "/capacity")
|
||||
batteries = string.format("[ %s %s%% ] ", filename, battery) .. batteries
|
||||
end
|
||||
end
|
||||
|
||||
-- Get wifi link quality
|
||||
|
@ -57,20 +57,20 @@ local winit = {}
|
|||
local wifi_string = ""
|
||||
local wifi = io.open('/proc/net/wireless', 'r')
|
||||
if (wifi ~= nil) then
|
||||
for line in wifi:lines() do
|
||||
table.insert(winit, line)
|
||||
end
|
||||
for line in wifi:lines() do
|
||||
table.insert(winit, line)
|
||||
end
|
||||
|
||||
-- what the fuck is lua regex.
|
||||
local wifi_regex = "%s(.*):.*%s(%d+)%."
|
||||
-- what the fuck is lua regex.
|
||||
local wifi_regex = "%s(.*):.*%s(%d+)%."
|
||||
|
||||
-- Assemble wifi into printable set of strings.
|
||||
for item = 1, #winit - 2 do
|
||||
for wif, wqual in winit[item + 2]:gmatch(wifi_regex) do
|
||||
wifi_string = wifi_string .. string.format("[ %s %s%% ] ", wif, wqual)
|
||||
end
|
||||
end
|
||||
wifi:close()
|
||||
-- Assemble wifi into printable set of strings.
|
||||
for item = 1, #winit - 2 do
|
||||
for wif, wqual in winit[item + 2]:gmatch(wifi_regex) do
|
||||
wifi_string = wifi_string .. string.format("[ %s %s%% ] ", wif, wqual)
|
||||
end
|
||||
end
|
||||
wifi:close()
|
||||
end
|
||||
|
||||
-- Get individual elements
|
||||
|
@ -85,31 +85,31 @@ local up_m = math.floor(((uptime % (3600 * 24)) % 3600) / 60)
|
|||
|
||||
local upstring = ""
|
||||
if up_d > 0 then
|
||||
upstring = string.format("%sd %sh %sm", up_d, up_h, up_m)
|
||||
upstring = string.format("%sd %sh %sm", up_d, up_h, up_m)
|
||||
elseif up_h > 0 then
|
||||
upstring = string.format("%sh %sm", up_h, up_m)
|
||||
upstring = string.format("%sh %sm", up_h, up_m)
|
||||
else
|
||||
upstring = string.format("%sm", up_m)
|
||||
upstring = string.format("%sm", up_m)
|
||||
end
|
||||
|
||||
local output = {
|
||||
{ "model", model },
|
||||
{ "distro", os_rel['PRETTY_NAME'] },
|
||||
{ "kernel", kernel },
|
||||
{ "shell", shell },
|
||||
{ "uptime", upstring },
|
||||
{ "bat", batteries },
|
||||
{ "wifi", wifi_string },
|
||||
{ "model", model },
|
||||
{ "distro", os_rel['PRETTY_NAME'] },
|
||||
{ "kernel", kernel },
|
||||
{ "shell", shell },
|
||||
{ "uptime", upstring },
|
||||
{ "bat", batteries },
|
||||
{ "wifi", wifi_string },
|
||||
}
|
||||
|
||||
for i, value in pairs(output) do
|
||||
local color = ""
|
||||
if i%2 == 1 then
|
||||
color = "\27[34m"
|
||||
else
|
||||
color = "\27[36m"
|
||||
end
|
||||
local color = ""
|
||||
if i % 2 == 1 then
|
||||
color = "\27[34m"
|
||||
else
|
||||
color = "\27[36m"
|
||||
end
|
||||
|
||||
print(string.format("%s%6s \27[37m-\27[37m %s", color, value[1], value[2]))
|
||||
print(string.format("%s%6s \27[37m-\27[37m %s", color, value[1], value[2]))
|
||||
end
|
||||
print()
|
||||
|
|
Loading…
Reference in a new issue