groundwater / node-bin-nsh

10 stars 5 forks source link

Use REPL module #3

Open piranna opened 10 years ago

piranna commented 10 years ago

By using the Node.js REPL module we get by free and heavily tested the readline and history and all the functionality available on the Node.js console, just would only need to set a custom eval() function to allow to instantiate system commands, but also we get a Javascript interpreter so we can use Javascript scripts and functions on the shell. For example, with some hacks, it would be feasable to do something like:

> ls -a  # Shell-like command
['.', '..']
> var a = ls('a')  // Javascript instruction
undefined
> console.log(a)
['.', '..']
> echo $a  // Echo would be an alias of console.log()
['.', '..']

The semantics would need a review, but but you can see what's the idea ;-)

groundwater commented 10 years ago

I like this idea.

I think it's parallel to nsh but I really like the idea of a JavaScript system REPL. CoffeeScript is a bit more terse however, and as much as I generally avoid it, it might make a better REPL.

There are a few difficulties around doing job-control, tty-stuff, and signal handling. Just warning you that there may be some madness going forward. You have to make sure that keyboard commands are sent to child processes such as vim when those programs are in the foreground.