[英]In conky, how do I nest a variable within a template?
In conky, how do I nest a variable within a template?在 conky 中,如何在模板中嵌套变量?
EXAMPLES:例子:
${template2 enp0s25} <- WORKS (fixed string)
${template2 ${gw_iface}} < FAILS (nested variable)
${template2 ${execpi 10 ls -d /sys/class/net/enp* 2> /dev/null | sed -e 's,/sys/class/net/,,'}} <- FAILS (nested variable command)
I've also tried (and failed):我也尝试过(但失败了):
${combine ${template2 ${gw_iface}}}
${combine ${template2} ${gw_iface}}
Here is "template2":这是“模板2”:
template2 = [[
${if_existing /proc/net/route \1}Wired Ethernet ("\1"):
- MAC: ${execi 5 cat /sys/class/net/\1/address} IP: ${addr \1}
- Max: ${execi 5 /sbin/ethtool '\1' 2>/dev/null | sed -n -e 's/^.*Speed: //p'}${goto 190}${if_match ${downspeedf \1} > 0}${font :bold:size=14}${endif}Down: ${downspeedf \1}kB/s${font}${goto 370}${if_match ${upspeedf \1} > 0}${font :bold:size=14}${endif}Up: ${upspeedf \1}kB/s${font}
${endif}]]
Thanks for the help.谢谢您的帮助。
Templates are a little limited as you cannot evaluate the parameters before they are passed through.模板有一些限制,因为您无法在参数通过之前对其进行评估。 One workaround is to use a bit of
lua
code to do the eval explicitly and then parse the template.一种解决方法是使用一些
lua
代码显式执行 eval,然后解析模板。 For example,例如,
conky.config = {
lua_load = '/tmp/myfunction.lua',
...
};
conky.text = [[
${lua myeval template2 ${gw_iface}}
]]
Create the lua file, /tmp/myfunction.lua
holding创建lua文件,/
/tmp/myfunction.lua
保存
function conky_myeval(tpl, var1)
v = conky_parse(var1)
cmd = "${"..tpl.." "..v.."}"
return conky_parse(cmd)
end
The lua
function takes the name of the template, tpl
, and the parameter to evaluate, var1
. lua
函数采用模板名称tpl
和要计算的参数var1
。 It evaluates the latter using conky_parse()
to, say, string "xxx", then constructs a new string "${template2 xxx}"
, which is parsed and returned as the value of the ${lua}
call.它使用
conky_parse()
将后者评估为字符串 "xxx",然后构造一个新字符串"${template2 xxx}"
,该字符串被解析并作为${lua}
调用的值返回。
The same can be done for the longer example ${execpi ...}
too.对于较长的示例
${execpi ...}
也可以这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.