When I use the accepted answer, the console is blocked until I close the corresponding tab in VS Code. Since I often want to keep the tab open in VS Code while I keep using the console, I came up with this workaround:
ls > t; code t; rm t
It redirects to file t
in the current directory, tells VS Code to open that file, and then deletes it. You will see the contents of the file in VS Code in a tab labeled t (deleted)
.
A slight delay (1 second works for me) is needed if VS Code isn't already open:
ls > t; code t; sleep 1; rm t
Notes
- I tested this on Windows 10 using either Git Bash or PowerShell 7.
- Of course, be careful with the name you use for the throwaway file so you don't overwrite a real file.
Edit: I made a function for this to throw in my PowerShell profile.
Function Out-Code {
do {
$filename = New-Guid
} while (Test-Path $filename)
$input > $filename
code $filename
Start-Sleep 1
Remove-Item $filename
}
Set-Alias oc Out-Code
Usage
ls | oc