5.4.1 • Published 8 years ago
@ygor/shell v5.4.1
@ygor/shell
A no-frills shell template tag. Built on promises to work wonderfully with async and await in Node.js 8 and above. Part of the Ygor toolkit.
Install
$ npm install --save @ygor/shellUsage
const shell = require('@ygor/shell');
const foo = 'hello world';
const bar = 'goodnight moon';
await shell`
echo ${foo}
>&2 echo ${bar}
`;
const result = await shell({ stdio: 'pipe' })`
echo ${foo}
>&2 echo ${bar}
`;
console.log(result.stdout, result.stderr);API
shell`cmd`: Promise
cmd{String}
Interpolates a string, escapes values to make them safe to run in the shell, then executes the command. Supports multi-line commands. Directs stdout and stderr to the parent process.
await shell`
echo ${foo}
>&2 echo ${bar}
`;
try {
await shell`exit 123`;
} catch (e) {
console.error(`Exited with code: ${e.code}`);
}shell(options): Function(strings, ...values): Promise
options{Object}- Seeexecaoptions.
Creates a template-tag function with the given options. Useful for overriding things like the current working directory or how stdio is handled.
const shellPipe = shell({ stdio: 'pipe' });
const process = shellPipe`echo hello world`;
process.stdout.pipe(process.stdout);
console.log(await process);MIT © Shannon Moeller