Round-trip to shell script

49 views
Skip to first unread message

Rob

unread,
Aug 13, 2019, 11:27:28 AM8/13/19
to leo-editor
This is probably a simple Python script, but my searches online have been more confusing than clarifying as I'm not experienced enough w/ Python to sort it all out. The few I tried didn't work.

I am (re)discovering how useful pandoc is and now use it frequently w/ stuff I write in Leo (mostly rst and md) to create .odt, docx, .tex and .html output. Current workflow:
  1. Write pandoc command line instructions in Leo (they can be quite long and I can save and use them again later).
  2. Copy node text to clipboard and paste into a Powershell window.
  3. Execute the pandoc command.
  4. If output is stdout, then copy output to clipboard and paste into another Leo node for additional work if necessary.
What would be cool and convenient is do all of that with one script, as in:

  1. Copy node text containing the pandoc commands (already have a script for that part).
  2. Send to shell and execute.
  3. Return result back to Leo into a new node (perhaps a child, perhaps not).
Seems there would be other use cases for sending commands to a shell and retrieving results back into Leo besides pandoc. Any suggestions on where to start?

Rob...

gar

unread,
Aug 13, 2019, 11:33:33 AM8/13/19
to leo-e...@googlegroups.com
Look at the plugins. 
I didnt try any, but looks like 'at_produce' or 'interact' plugins are for you.

вт, 13 авг. 2019 г. в 18:27, Rob <lar...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/8572044a-9fc4-4254-ba7e-6c0bdcba5f5d%40googlegroups.com.

Rob

unread,
Aug 13, 2019, 11:39:08 AM8/13/19
to leo-editor
Thanks, will take a look.

Rob

unread,
Aug 13, 2019, 11:57:03 AM8/13/19
to leo-editor
There was also a reference to the leoscreen.py plugin, but that won't load w/o errors; perhaps not compatible w/ Python 3?

Chris George

unread,
Aug 13, 2019, 12:09:51 PM8/13/19
to leo-editor
This is an @button I use to run wordnet on a selected word.



w = c.frame.body.wrapper


p = w.getSelectedText()


message = p.replace('"', "'")


command = '/usr/bin/wn %s -over' % message




c.controlCommands.executeSubprocess(


    event=None,


    command=command,


)


The output goes to the log pane, and more importantly, to the terminal where I started leo from.

Running leo using a redirect to a log file captures stdout. From there it is pretty simple to create an @file that can be updated via "refresh from disk" to get the output into a node.

ie. ./launchLeo.py >sessionlog.txt

HTH,

Chris

Terry Brown

unread,
Aug 13, 2019, 12:26:52 PM8/13/19
to leo-e...@googlegroups.com
On Tue, 13 Aug 2019 08:57:03 -0700 (PDT)
Rob <lar...@gmail.com> wrote:

> There was also a reference to the leoscreen.py plugin, but that won't
> load w/o errors; perhaps not compatible w/ Python 3?

Not sure about Python 3 compatibility, but it works exclusively with
the `GNU screen` terminal multiplexer, a unix thing. Very handy in
that context because you can interact with any command line driven
thing (Python, R, SQL, Bash, etc., etc.) from the Leo body pane, but no
use outside that context.

Cheers -Terry

Rob

unread,
Aug 13, 2019, 12:30:12 PM8/13/19
to leo-editor
So, not useful for Windows, then. Same also applies to interact.py as it's for bash commands.

I did find that at_produce.py works (so far anyway).

Rob...

vitalije

unread,
Aug 13, 2019, 3:49:44 PM8/13/19
to leo-editor
You can try md_docer.py plugin. I remember writing it for someone with similar problem. Using it you can define one or more transformer scripts with the headline like "@transformer mytransformer". This script has access to g, c, p and out vars. Out is a file like object. Script should write its output to out. Nodes with the headline like " @transform-node mytransformer(somegnx)" will have the output of transformation mytansformer of node with the given somegnx.

Transformations can be executed as minibuffer command or by default on every save.

HTH Vitalije

Rob

unread,
Aug 14, 2019, 8:10:54 AM8/14/19
to leo-editor
Thanks, will look at that one also.

Rob...
Reply all
Reply to author
Forward
0 new messages