Skip to content

Repository files navigation

bashscript

A small and minimalist REPL shell, and a very lightweight JavaScript library meant to convert Operating System commands to functions.

TLDR

import{cmd}from'bashscript';awaitcmd.echo("Grr Grr Meow!").exe;// Grr Grr Meow!

Installation

npmibashscript

REPL Shell

npmi-gbashscript # installbashscriptREPLshell$bashscript # entershell>process.titlenode>process.uptime()22.950190303>cmd.echo('Meow!').value()Promise{<pending>}>awaitcmd.echo('Meow!').value()'Meow!'

Advanced REPL

>constcommand=cmd.echo('Foo');undefined>commandShell{}>awaitcommand.value();'Foo'>command.result{command: 'echo Foo',exitCode: 0,stdout: 'Foo',stderr: '',all: undefined,failed: false,timedOut: false,isCanceled: false,killed: false}

Usage

import{cmd,exe}from'bashscript';const{ echo }=cmd;constresult=awaitexe(echo("Meow!"));assert.equal(result,"Meow!");
import{cmd}from'bashscript';constresult=awaitcmd.echo("Meow!").value();assert.equal(result,"Meow!");
import{cmd}from'bashscript';constresult=awaitcmd.echo("Meow!").exe;assert.equal(result,"Meow!");

Pipeline Example

import{cmd}from'bashscript';const{ pipeline, cat, echo, tr, grep }=cmd;constresult=awaitpipeline(cat(echo('package.json')),tr('"[a-z]"','"[A-Z]"'),grep('NAME')).value();assert.equal(result,' "NAME": "BASHSCRIPT",')
import{cmd}from'bashscript';const{ pipeline, cat, printf, dirname, readlink, which, grep, head }=cmd;constresult=awaitexe(pipeline(cat(printf("%s",dirname(readlink('-f',which('npm'))),"/../package.json")),grep('name'),head('-n',1)));assert.equal(result,' "name": "npm",')
import{cmd}from'bashscript';const{ pipeline, cat, printf, dirname, readlink, which, grep, head }=cmd;constresult=awaitpipeline(cat(printf("%s",dirname(readlink('-f',which('npm'))),"/../package.json")),grep('name'),head('-n',1)).value();assert.equal(result,' "name": "npm",')
import{cmd,pipeline}from'bashscript';// a pipeline helper can also be imported directly from the bashscript module.const{ cat, printf, dirname, readlink, which, grep, head }=cmd;constresult=awaitpipeline(cat(printf("%s",dirname(readlink('-f',which('npm'))),"/../package.json")),grep('name'),head('-n',1)).value();debug(result);assert.equal(result,' "name": "npm",')

Debugging Example

#!/usr/bin/env -S node --trace-uncaught
import{inspect}from'util';import{cmd}from'../index.js';const{ montage }=cmd;constfiles=['a.png','b.png','c.png'];consttile=2;constfilePath='/tmp/test.jpg';constcommand=montage({'-background': '"#212529"'},
...files,{'-geometry': '320x230','-tile':`${tile}x`},filePath);console.log(awaitcommand.string);// await command.exe; // to execute;

prints

montage -background "#212529" a.png b.png c.png -geometry 320x230 -tile 2x /tmp/test.jpg

Namage

Not related to Bash the GNU Project's shell (the Bourne Again SHell), this is a JavaScript library that automagically converts system commands to JavaScript functions (Think "bash, verb: strike hard and violently");

History

Need for OS command integration arose from development of https://catpea.com, I was unable to locate small enough solutions that worked well for me. I came across proxy-www and ended up creating munchhausen and later bashscript.

About

A small and minimalist REPL shell, and a very lightweight JavaScript library meant to convert Operating System commands to functions.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages