dx_over_dt
dx_over_dt

Reputation: 14318

Open a new file in VS Code with contents

I want to get some text from the output of a shell command and then open code to a new file with that contents.

My first attempt was to pipe the output directly into code, but this didn't work.

echo foo | code

My current "solution" is to redirect the output to a tmp file, open tmp in code, and then delete tmp.

echo foo > tmp; code tmp; rm tmp

This is tedious and has the ugly effect of showing that the file has been deleted in the tab:

deleted tmp file

There must be a better way.

Upvotes: 2

Views: 295

Answers (1)

dx_over_dt
dx_over_dt

Reputation: 14318

Turns out there is! It's an advanced technique I like to call Reading the Error Message™. 🤦‍♀️

echo foo | code
Run with 'code -' to read output from another program (e.g. 'echo Hello World | code -').

The solution:

echo foo | code -

Stack Overflow, you truly are the best rubber duck.
Relevant: Stack Exchange has been taken over by a rubber duck!

Upvotes: 3

Related Questions