4 ms·
I have been thinking that JS template literals could be a great replacement for shell programming, allowing you to make more powerful syntax to emulate a lot of
by DanielHB 3y ago
I have been thinking that JS template literals could be a great replacement for shell programming, allowing you to make more powerful syntax to emulate a lot of bash useful things while still having a lot of a proper programming language power
for example:
import { jsh, cat, grep, PipeOutput } from 'jsh;
// type PipeOutput = { stdout: ReadableStream, toString: () => Promise<string>, extra: Record<string,any> }
function countLines(input: PipeOutput, argv: string[]): PipeOutput {
// ...
}
const textToLookFor = process.argv[1]
const output: PipeOutput = jsh`${cat} file.txt | ${grep} ${textToLookFor} |
${countLines}`
console.log(output.toString())