Wondering what’s next for npm?Check out our public roadmap! »

    @ygor/shell

    5.4.1 • Public • Published

    @ygor/shell

    NPM version Downloads Build Status Coverage Status

    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/shell

    Usage

    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

    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);

    ygor


    MIT © Shannon Moeller

    Install

    npm i @ygor/shell

    DownloadsWeekly Downloads

    8

    Version

    5.4.1

    License

    MIT

    Unpacked Size

    4.47 kB

    Total Files

    3

    Last publish

    Collaborators

    • avatar