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.27k stars 620 forks source link

Substitute for $pre_exec for 2.0.0pre and higher? #62

Closed andreas--e closed 10 months ago

andreas--e commented 10 years ago

Well, I've just encountered by testing my fresh build with some old .conkyrc config files, that $pre_exec got removed at some point. Why, actually?

$exec and friends do NOT do what I want, because I really only want to execute a certain shell command ONCE. And $pre_exec was perfect for this task. So I wonder why the decision got made to remove a great feature that has been implemented since 2004.

Tucos commented 10 years ago

You should note that 2.0.0pre is pretty much a rewrite, rather than a continuation of conky. That said, $pre_exec was removed in commit b96f112, with the following reasoning: "I also removed the $pre_exec variable, because one can use lua to generate the config on the startup, if one wants to.".

andreas--e commented 10 years ago

Frankly, I did read about this reasoning, but it made not the slightest sense to me. Generate what? How? Why? Before removing such important and well-established variable, I do expect from the person who removes it an explanation that goes beyond a terse, incomprehensibly "murmured" phrase. Since in fact it will mean that zillions of scripts worldwide will have to be modified.

And yes, I'm now "back" to 1.9.1 (git), since 2.0.0pre is way too far off: while I was able to transform my old .conkyrc to the new LUA format, I regret to say that transparency doesn't work anymore in v2pre, but shows black although this is not the actual black background color. (Changed it to something weird and it stayed black, hence I assumed the black is due to the malfunctioning transparency.)

Tucos commented 10 years ago

The sentence I quoted suggests that the thought was that the config is lua, and thus lua can determine the value of that which used to be in $pre_exec and then substitute it in TEXT. I agree that it should not have been removed at all, and I'm not convinced it was thought through much either. 2.0.0 is/was more of a playground (especially back then).

andreas--e commented 10 years ago

I agree that it should not have been removed at all

Which is already the gist of my plead. OK, if 2.0.0pre is really just meant to play around with ... no problem BUT then 1.9.1 ought to be 'master' and 2.0.0pre should be given something in the sense of 'experimental'. Because git newbies might simply mistake the 2.0.0pre for "latest devel" without being aware of the fact that seemingly "old" 1.9.1 is still actively developed; and above all that this is the only devel version meant to be used. This is not a rant; it's a suggestion.

Vincent-C commented 9 years ago

Forwarding a bug report (#791718) I received from a Debian user:

I noticed that the pre_exec variable has been removed, without providing anything with an equivalent behavior. This seems to be confirmed by: https://github.com/brndnmtthws/conky/issues/62 https://github.com/brndnmtthws/conky/commit/b96f112106ea43dda5b5747bc315a2b76ba9da8f

The commit description says that the pre_exec variable has been removed "because one can use lua to generate the config on the startup, if one wants to".

Oh well, if one knew how to program in Lua, one could use Lua to generate the config on startup! I have currently no knowledge about Lua, so I am a bit lost without some example in the documentation.

I failed to find any relevant explanation on how Lua could be used to emulate the behavior of pre_exec...

My attempt (after converting my .conkyrc to the new Lua-based syntax) is the following:

  $ cat .config/conky/conky.conf 
  -- vim: syntax=lua

  conky.config = {
    -- many settings...
    lua_startup_hook = 'conky_cow', -- append fortune said by a cow
    };

  -- stuff to be formatted on screen
  conky.text = [[
  a lot of stuff...
  ${color green}
  ]];

  function conky_cow()
      o = io.popen('fortune -s | cowsay', 'r')
      conky.text = conky.text .. o:read('*a')
  end

Unfortunately, it does not work and I do not know why. In case you happen to know how I can emulate pre_exec, please help me, and/or forward my bug report upstream.

Thanks for your time!

P.S.: my current workaround is to use execi with a long interval:

${color green}${execi 65000 fortune -s | cowsay}

It's much simpler than any Lua-based solution, but it does not do exactly what I want... I still wonder why pre_exec has been removed: it was so simple and useful! :-(

asl97 commented 7 years ago

@Vincent-C It's not working for your script is because the function ain't getting call. from the quick few tests I did, it seem lua_startup_hook need the function to be in another file that is loaded using lua_load, not really sure how the hook function thingy all works cause I rather just directly use the config as lua since it is lua.

Basically just call the io.popen stuff and concat it into conky.text

conky.text = [[
a lot of stuff...
${color green}
]];

o = io.popen('fortune -s | cowsay', 'r')
conky.text = conky.text .. o:read('*a')

@labath Honestly, I am rather disappointed at how long this issue is left unaddressed, with no basic example since it's your commit which removed it.


everyone else: conky.text is just a string, http://lua-users.org/wiki/StringsTutorial you can call a function and then concat the output to it. (see Concatenation in the tutorial)

an basic function which takes a string, execute it and return the output

require 'io'

function pre_exec(cmd)
    local handle = io.popen(cmd)
    local output = handle:read("*a")
    handle:close()
    return output
end

usage:

conky.text = pre_exec("lsb_release -sd || cat /etc/*release")..[[
${hr}
System $alignr ${nodename}
Kernel ${alignr} ${kernel}
-- additional stuff
]]
lasers commented 6 years ago

@su8 Thoughts?

su8 commented 6 years ago

You can close this issue, as the pre_exec option has been removed in favour of lua, which both people demonstrated usage examples. Even if we bring back the pre_exec the code will be the same, popen() call and read().

lasers commented 6 years ago

Okay, we'll close this issue. I think we need to document well-demonstrated examples in the man page sooner or later because this is still going to be confusing for everybody.

Then again, everybody I know is still confused with their life.

emk2203 commented 6 years ago

Even after reading this a couple of times, I am still confused about where to put the function, how to concatenate so that the text is in the middle of the output, not just at the beginning, how to align the text as desired, how to format it and probably a lot more.

This leaves more open questions than it should.

plikhari commented 6 years ago

This is a very trivial issue if you look at it - we want to run anything only once - it depends on a few issues::

If you give ${execi} 100000 abc as the command - that is about 27.78 hours - that command will run once in that many hours.

This command or any LUA script will get evaluated every update_interval to figure out what is to be done with this line request.

Even though I have created a LUA alternative - (every conky function can be re-created in LUA with a very tiny overhead as compared to the original C++ code) - I no longer use it as I give a rather large time interval if ${pre_exec} is required.

use ${if_running} to check if a process is running and then let your command fire.

So if we agree - then ${pre_exec} is really not required.

emk2203 commented 6 years ago

@plikhari: You leave out the option that whatever is run with ${pre_exec} can only be run at startup. Trivial example: The time the computer was booted, or a sensor value at startup. If you re-run this, the value will be wrong.

If you really want to get rid of ${pre_exec}, although I cannot see a reason myself, please document the replacement option well. In this case, it should be option 1: ${execi} 10000 for things which can be repeated and option 2: whatever lua offers for things which should only run once, period.

Please keep in mind that most users of conky use it once to set their configuration and afterwards don't touch it for a very long time. This would help a lot of people out there. The new way is not as intuitive as the old option was.

plikhari commented 6 years ago

It is not that anyone wants to get rid of ${pre-exec} - it is already gone since 1.10.0 !!

You leave out the option that whatever is run with ${pre_exec} can only be run at startup.

That was the basic understanding for ${pre-exec}

A simple sh solution like this will also work - this is a rock bottom non LUA idea - also see #318 and why I do not use ${if_existing } - the file name used below is of my choosing - you may use whatever makes you happy: ${texecpi 10000 if [ ! -e /tmp/t001conky ]; then do something here; touch /tmp/t001conky; fi }

This will behave exactly like ${pre_exec}

github-actions[bot] commented 11 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 10 months ago

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