
Show HN: Crsh – A JavaScript based command line shell - _carl_jung
https://crwi.uk/2020/07/12/crsh.html
======
tannhaeuser
Hey I like it! But is it deno-only or also working on Node.js? The latter
would be much _much_ more useful for me.

~~~
_carl_jung
Thanks! It's Deno only I'm afraid. I'm interested in what would make it more
useful for you as a Node project (so that I can gather info on the sorts of
use cases that would be good).

~~~
tannhaeuser
Hi thanks for the response. My use case would be to execute relatively small
snippets of shell code/one-liners as part of an asset management pipeline
without having to "shell-out" and invoke an external process, mostly at
deploy-time, in a portable fashion, such as rendering a static HTML file upon
change of dependent data, or rendering an image/icon from a vector format
representation, and similar tasks. Requirements for shell control constructs
are modest, but piping and redirection should work, as well as limited shell
var/macros expansion, and maybe if/then. In Node.js-land, there's the shelljs
package which is both an API for (synchronous-only AFAICS) shell-like ops (as
in "shelljs.ls('file.???')" and a (very limited) shell syntax parser that
could call those funcs from a string ("ls file.???") like yours as far as I
can understand, but I guess yours is already more capable then the one shelljs
uses. Still, shelljs is used as a dependency by quite a number of high-profile
packages.

Node.js is much more useful simply because everything in js-land (asset
management tools, web server backends) runs on Node.js rather than deno :)

~~~
_carl_jung
Sorry for the late response.

> execute relatively small snippets of shell code/one-liners as part of an
> asset management pipeline without having to "shell-out" and invoke an
> external process

This is indeed a small part of the value of my shell, though I wouldn't view
it as the primary reason. I'm trying to make a nice experience for an
interactive command line shell first, then will think about scripting use
cases.

Blurring that line between shell + scripting is my intention, so it would be
good to capture your case here at some point.

> Requirements for shell control constructs are modest, but piping and
> redirection should work, as well as limited shell var/macros expansion, and
> maybe if/then.

I'm struggling to understand one detail of your use case here. Is this a
script (stored as some e.g. .js file), or something you'd be executing
interactively? If the former, my shell does have as part of its library a
suite of tools for executing shell commands (including piping + redirect) from
within the Deno runtime. That would make something like the following
possible:

const jsFilesInDirectory = await exec('ls | grep .js');

if (jsFilesInDirectory.includes('index.js') {

    
    
      // some logic
    

}

The above is also strikingly similar to shelljs, but my solution differs in a
key way: where shelljs is re-implementing many commands, I've developed logic
for parsing and evaluating any shell-like "pipe-separated" commands.

In any case, the primary intention of my project is to create an interactive
shell, not a scripting language. That said, it would be possible to tease out
and reproduce my logic to parse and execute piped commands in Node.js, to
allow for a slightly more capable "shelljs" clone.

Hope that helps.

~~~
tannhaeuser
Yes, as I looked into your code, I was even tempted (in thought only, eg
subconsciously feasability-checking) to fork/rip your shell syntax parser and
plug it into shelljs to replace theirs ;)

To clarify, in my use case, the native asset meta-format for declaring assets
and their relationships has a "field" where you can put in an external command
to prepare the asset (such as minifying, sass compilation). Like in a
Makefile.

