Working with a custom interactive shell - how?

Using Komodo IDE 9.3, I want to:

  1. configure a custom interactive shell, ocaml in this case, but I can only select Tcl Ruby Python Perl
  2. I want to select code in the editor window and send it with a keystroke to the ocaml shell for evaluation.

I am already stuck with 1. Any hints would be appreciated.


P.S. this is possible with editor kate (KDE) by opening a terminal, and sending highlighted text to the terminal. But Komodo should be superior…

Tools > Run Command. I don’t use ocaml shell, but this is what I would use for gnome-terminal:

gnome-terminal -e "bash -c \"%s; exec bash\""

You can then hit the “Add to Toolbox” checkbox to save this command to your Toolbox, so you can easily trigger it again.

And it is! Don’t assume :wink:

Btw if you want to get more creative you could also do this programmatically, here is a sample userscript that handles quotes:

var selection = require("ko/editor").getSelection().replace(/("|')/g,'\\\\\\$1');
require("ko/shell").exec('gnome-terminal -e "bash -c \\"'+selection+'; exec bash\\""', {});

Yeah it gets a little crazy with the backslashes, thank gnome-terminal and the fact that I’m only giving you a quick demo for that :wink:

Okay, number 1 was easy, just run the command. I have never used that because I always had a terminal handy (and with focus follows mouse very easy to activate).

And I always did copy and paste, of course, middle button.

But now I found in kate the function “send selection to terminal”, mapped it to a key, and it does send. And the terminal keeps running, so I incrementally add functions and tests to the running program shell (REPL in other languages). It is like copy with a shortcut paste - it simply is faster.

Your code snippet always starts a new shell with the selection as input, thank you, noted.

I suspect Kate may be giving you a more “targeted” solution, whereas ours is more low level in that it’s up to you to define how the command executes exactly. So for our use-case you need to keep in mind that once a command ends your terminal will close. That’s why my example command has ;exec bash at the end.

Be sure to also check out the Shell scope, if you use Komodo IDE. It allows you to run terminal commands as well.