How do I call a function after loading it in conkyrc? For example:
I'm trying to get the active interface name which is returning properly
${lua conky_findInterface} #gives me device name
function conky_findInterface()
local handle = io.popen('ip a | grep "state UP" | cut -d: -f2 | tr -d " "')
local result = handle:read('*a'):gsub('\n$','')
handle:close()
return result
end
How do I use it more dynamically? Such as :
${if_up ${lua_parse "${lua conky_findInterface}"}} #this does not work nor do my other variations
Hello
${else}
Goodbye
${endif}
It seems that a conky if statement argument can't be a string, so a string returned by a Lua function won't work. For example, where my interface is "enp2s0", the statement
${if_up enp2s0}
will work, but${if_up "enp2s0"}
will not.A workaround is to include the entire conky if statement in a Lua function. For example:
The function
conky_ifupInterface()
is then called inconkyrc
with the line:Unfortunately, just returning the first line of the if statement isn't sufficient to satisfy the
lua_parse
operator. The entire statement through the${endif}
has to be returned.Note that the current implementation of
findInterface
will cause the conky config to crash on a call toconky_ifupInterface
if the interface is down becausefindInterface
will return a null value, resulting in the if statement beginning with${if_up }
. To make it work for testing, I did the following quick and dirty bit...Yuck! I'm sure you can do better. :^)