Skip to content

RFC: specify redirections with JS object parameters #800

Description

@nfischer

I proposed this idea a while ago, but I can't remember where. I'm looking for comments/feedback.

The basic idea is to replace this:

shell.grep('foo', 'file.txt').to('other.txt');

with

shell.grep('foo', 'file.txt', { '>': 'other.txt' });

What does this fix?

It's currently not possible to mute echo() with redirection, which is kind of awkward. With this syntax, we can add support in src/common.js to temporarily add shell.config.silent = true. Then we just need to write echo() to respect that value. Voila.

New features?

This opens the door to some cool new features. Some ideas:

shell.rm('missing-file.txt', { '2>': 'error.log' }); // redirect stderr
shell.cat('first.txt', { '>>': 'second.txt' });
shell.cp('-r', 'src', 'out', { '2>&1': /* not sure what should go here :( */ });
shell.tail('file.txt', { '>': 'stdout.txt', '2>': 'stderr.txt' });

A downside to this design is that we cannot support multiple redirects (e.g. echo foo > file1.txt > file2.txt).

Alternate ideas for syntax

shell.rm('missing-file.txt', { 2: 'error.log' }); // '2' instead of '2>'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions