brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

INCLUDE statement for conky.config section #364

Closed wlatendresse closed 7 months ago

wlatendresse commented 7 years ago

I think it would be quite handy to have INCLUDE statement to import generic settings (like colors, fonts ...) used in all windows if you have multiple conky instances with multiple configurations running on a machine. It would make life much easier for all people who create themes as well I guess.

I know you could argue that this is easily achievable by usage of multiple parts of a config file whic hcould be joined by any means like cat before the actual start of the conky instance, but this is of course not quite the same in my eyes, especially when it comes to creation of a new theme where you can easily edit a config right now and conky will autodiscover the change and reload it's configuration.

BTW: Thanks for this great program, habe been using gkrellm until now, but apparently I HAD to purge it from my SSD after having been playing around with conky for some hours ;)

ericx commented 7 years ago

Just poking around and learning myself; but I'm modestly using Lua to compose conky.config. The config file is interpreted by Lua; so you can do anything the language supports (with the exception of 'conky_parse()' et al. which seem to only be available in scripts which you "lua_load").

conf_dir = os.getenv("HOME") .. '/.config/i3/conky_bar'

conky.config = {
   out_to_x        = false,
   out_to_console  = true,
   short_units     = true,
   update_interval = 1,
   lua_load        = conf_dir .. '/conky_json_load.lua',
}

So, in the above, you could add:

dofile(conf_dir .. '/my_favorites_settings.lua')

in which you could compose any vars you want to "include" repeatedly.

I wouldn't presume to speak for Brenden, but judging from threads like https://github.com/brndnmtthws/conky/issues/62, it would seem that the design policy is somewhat: "If the embedded interpreter can handle it, then a feature doing the same thing is superfluous."

Lua is a bit light in syntactic sugar, but it doesn't seem to suck as interpreters go.

nabajour commented 6 years ago

I'm not a Lua wizard, just learned a minimum while doing this, so maybe this is overly complicated and overkill. But I'm not sure dofile actually defines its variables in a namespace that gets imported in the main namespace (and if actually Lua knows about namespaces) and adds it to conky.config namespace. It didn't seem to find variables from dofile in the main config. I got this to work this way:

conky.conf:

conf_dir = os.getenv("HOME") .. '/.config/conky/'

config = {
own_window = true,
....
blah = true
...
};

function merge(a, b)
    if type(a) == 'table' and type(b) == 'table'
    then
    for k,v in pairs(b)
    do
        if type(v)=='table' and type(a[k] or false)=='table'
        then
            merge(a[k],v)
        else
            a[k]=v
        end
    end
    end
    return a
end

dofile(".config/conky/conky_local.lua")
config_local = cnf()
conky.config = merge( config, config_local )

and conky_local.lua:

function cnf ()
     local_config = {
     font = "DejaVu Sans Mono:size=12",
     minimum_width = 2560,
         maximum_width = 2560,
     }
     return local_config
end

conky_local.lua defines a function that returns a table with the settings we want to append. Then the two tables get merged in one table that gets assigned to conky.config.

madobet commented 4 years ago

I'm not a Lua wizard, just learned a minimum while doing this, so maybe this is overly complicated and overkill. But I'm not sure dofile actually defines its variables in a namespace that gets imported in the main namespace (and if actually Lua knows about namespaces) and adds it to conky.config namespace. It didn't seem to find variables from dofile in the main config. I got this to work this way:

conky.conf:

conf_dir = os.getenv("HOME") .. '/.config/conky/'

config = {
own_window = true,
....
blah = true
...
};

function merge(a, b)
    if type(a) == 'table' and type(b) == 'table'
    then
  for k,v in pairs(b)
  do
      if type(v)=='table' and type(a[k] or false)=='table'
      then
          merge(a[k],v)
      else
          a[k]=v
      end
  end
    end
    return a
end

dofile(".config/conky/conky_local.lua")
config_local = cnf()
conky.config = merge( config, config_local )

and conky_local.lua:

function cnf ()
   local_config = {
   font = "DejaVu Sans Mono:size=12",
   minimum_width = 2560,
         maximum_width = 2560,
   }
   return local_config
end

conky_local.lua defines a function that returns a table with the settings we want to append. Then the two tables get merged in one table that gets assigned to conky.config.

There is not need of function cnf(), simply define

local_config = {
    font = "DejaVu Sans Mono:size=12",
    minimum_width = 2560,
    maximum_width = 2560,
}

in conky_local.lua and then use it in conky.conf:

dofile(conf_dir ... "conky_local.lua")
conky.config = merge( config, local_config )

is enough.

You can even put the merge_conf call into conky_local.lua to make the configuration totally modularized:

function merge_conf(tab1, tab2) --> merge tables if type(tab1) == 'table' and type(tab2) == 'table' then for k,v in pairs(tab2) do if type(v)=='table' and type(tab1[k] or false)=='table' then merge_conf(tab1[k],v) else tab1[k]=v end end end return tab1 end

dofile(conf_d ... "conky_local_1.lua") dofile(conf_d ... "conky_local_2.lua") -- ...

LinuxOnTheDesktop commented 3 years ago

This page says there is an include function (but I cannot get it to work).

bassicallychris commented 2 years ago

This page says there is an include function (but I cannot get it to work).

I bump this. I see the include but when I use ${include ~/.conf/conky/extra-conky-config-file} it just displays ${include} Meanwhile the description says:

Loads the config file at path, places the config settings behind the config settings in the original config and places the vars where the include var stood.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment, or this issue will be closed in 30 days.

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 30 days with no activity.