Conky & Lua

Thanks to this article I became aware of how flexible conky's Lua configuration format is - it is effectively a Lua script. This opens almost endless new possibilities that go far beyond mere modularisation.
For example, I could grab values from the system and design my conky accordingly, like I have done with this conkyrc:

lua
-- get current GTK theme cmd = io.popen('grep "^[[:space:]]*gtk-theme-name" "$XDG_CONFIG_HOME/gtk-3.0/settings.ini" | cut -d\\= -f2') theme = cmd:read('*a') io.close(cmd) -- try to find colors.lua in $HOME's GTK theme folder... theme_file = os.getenv("HOME") .. '/.local/share/themes/' .. string.gsub(theme, '[\n]+', '') .. '/conky/colors.lua' -- ...test if file exists and is readable f = io.open(theme_file,"r") if f~=nil then io.close(f) -- "source" it dofile(theme_file) else -- fallback to default colors foreground = "D8DEE9" -- ... white0 = "ECEFF4" -- ... white1 = "ECEFF4" -- etc. ... end -- more variables to be used inside conky.config largefont = 'Cascadia Mono:style=ExtraLight:size=20' conky.config = { default_color = '#' .. foreground, color0 = '#' .. white0, use_xft = true, -- header -- \1 - header text template0 = [[$color0${font ]]..largefont..[[}\1$font${voffset 8}$color]], -- epsi-rns.github.io/desktop/2019/06/11/modularized-conky.html template1 = os.getenv("HOME") .. '/documents/Notes/.conky-notes.txt', }; conky.text = [[ ${template0 Latest\ journal\ entries} ${journal 20} ${if_empty ${cat ${template1}}}\ $else\ ${template0 Notes} ${cat ${template1}}${endif} ]];

(I apologise for my poor Lua scripting skills, I'm only getting started with this.)

In the top section (all above conky.config) it

  • reads the current GTK theme (by calling external utilities, but this is also possible in pure Lua)
  • looks for a file called conky/colors.lua under the theme's folder
  • if found:
    • "sources" it (the dofile function)
  • else:
    • loads default colors

It also defines a custom font.

All these variables can be used inside the conky.config and conky.text sections.

This allows to automatically theme conkys in accordance with desktop themes, something I've been dreaming of for a long time!
Of course you have to first create a colors.lua for each theme (but even that could be automated). I currently use the Nordic theme, and have placed colors.lua in $HOME/.local/share/themes/Nordic/conky/colors.lua, and it contains this:

lua
-- from Nord palette foreground = "D8DEE9" background = "2E3440" black0 = "434C5E" red0 = "BF616A" green0 = "A3BE8C" yellow0 = "EBCB8B" blue0 = "81A1C1" magenta0 = "B48EAD" cyan0 = "88C0D0" white0 = "ECEFF4" black1 = "4C566A" red1 = "BF616A" green1 = "A3BE8C" yellow1 = "EBCB8B" blue1 = "81A1C1" magenta1 = "B48EAD" cyan1 = "8FBCBB" white1 = "ECEFF4"