Beside previous simple loop that is used as Internal Command,
this tutorial also provide Conky as External Command
in asset directory.
I made it as simple as possible.
Ruby provide a dozen Pipe mechanism. Here we have system,
spawn, and shell.transact.
These three related to system shell.
Using system shell is simple and straightforward.
But it does not have any ability,
to stream internal function process,
that required later on this article.
This step is overview of Pipe between two external command.
This short script is using conky
as pipe source feed and less as pipe target.
Showing time and date forever in the console.
This infinite pipe run in time-less fashioned.
I add _ dir _, relative to the Ruby source,
to locate the conky script assets.
First IO.popen using cmdout create stdin.
Second IO.popen using cmdin create stdout.
Ruby act as middle man, stdout read by Ruby, and put in stdin.
A Unidirectional Pipe from Internal Function
Again, Ruby provide a dozen Pipe mechanism.
Here we have Open3.pipeline_w, IO.pipe,
IO.popen, and PTY.spawn.
These three related unidirectional capability that we need.
Or to be precise, they have bidirectional capability.
Using internal function as source feed
to external command is straight forward.
This should be self explanatory.
The same as previous.
But instead of reading from stdout,
it is managed by internal process using stdin.puts.
Fork Overview
This step use internal function as source feed,
as continuation of previous step.
To avoid complexity of longer script,
most code is written inside function
This step use dzen2, with complete parameters.
This dzen2 is forked, running in the background.
Detached from the script,
no need to wait for dzen2 to finish the script.
This step also add system command that kill
any previous dzen2 instance. So it will be guaranteed,
that the dzen2 shown is coming from the latest script.
Any code inside the fork block
executed under new child process with new pid
The child process could be detached from parent process
using Process.detach(pid).
Polishing The Script
This step, we use conky again, as a source feed.
And also parameterized dzen2 as continuation of previous step.
This step add optional transset transparency,
detached from script. So we two forks, dzen and transset.