Custom terminal as VSCode extension? - visual-studio-code

Can a VSC extension add an entry in the "New Terminal" menu and pipe args into Python or some other terminal program?

There are examples available on the VSC samples repository:
https://github.com/microsoft/vscode-extension-samples/blob/main/terminal-sample/src/extension.ts
https://github.com/microsoft/vscode-extension-samples/pull/449/files

Related

Is there a way to programmatically open a NEW built-in terminal in VSCode from the terminal/bash?

Specifically I'd like to run a terminal command from vscode's built in terminal and have that command open another new vscode built-in terminal. Is this possible?
This is related to my question here - https://github.com/mklement0/ttab/issues/51#issuecomment-1372825316
Say I have the following command in my package.json scripts:
"sayHello": "ttab echo hello",
And I run npm run sayHello from the vscode integrated terminal. Is
there a way to have it so that the new terminal that is created is
created within the integrated terminal instead of from (in my case)
the default mac terminal application?

How can I open a file in visual studio code's text editor from the visual studio code's terminal?

Trying to start with VSC and want to know if there is a shortcut to open VSC's text editor from it's terminal ?
Assuming you have added vscode to your PATH variable during the installation process you can just type code path/to/your/file. This will open the file in the current vscode instance.
If you want it to open in a new window add the -n flag. For example code path/to/your/file -n

How to run SML REPL in Visual Studio Code

I am trying to use SML/NJ in Visual Studio Code editor but can't figure out how to run SML REPL in Visual Studio Code. I have installed SML extension in Visual Studio Code but no documentation is available. How to configure SML in Visual Studio Code?
Have you installed latest SML/NJ version ? Download from here https://www.smlnj.org/dist/working/index.html
Install it.
Now open VSCode, go to menu Terminal > New terminal.
In terminal type sml and confirm command. It will enter the SML/NJ REPL mode.
On linux, you can open a bash terminal with Ctrl-j and use the sml command (if you have it installed) to get an integrated REPL.
To run REPL one can set-up a task for VSCode like this:
{
"label": "SML REPL",
"type": "shell",
"command": "sml ${file}",
}
this task will run current file with REPL.
It is also possible to use problem matcher and then issues (at least with syntax) will be highlighted directly in editor.

How to set mintty.exe as the default terminal on Windows?

I am trying to set the https://github.com/mintty/mintty terminal installed by Cygwin as the default Visual Studio Code terminal with:
"terminal.integrated.shell.windows": "D:\\Cygwin\\bin\\mintty.exe",
But it opens the Mintty.exe terminal on a new window, instead of show it as an embedded console.
Related thread I found about it:
How to change the integrated terminal in visual studio code or VSCode
How to Integrate babun shell in VS code
Is it possible to configure Babun/ZSH for the integrated terminal on Windows?
How to integrate terminal whth babun on windows?
You should use "D:\\Cygwin\\bin\\bash.exe" instead of mintty
cheers.
There are two terminal settings, you may want set them like this:
"terminal.external.windowsExec": "D:\\cygwin64\\bin\\mintty.exe",
"terminal.integrated.shell.windows": "D:\\cygwin64\\bin\\bash.exe",

How to open a file from the integrated terminal in Visual Studio Code?

Is there a way of opening a file from the terminal in Visual Studio Code that opens in the same vscode instance that runs the terminal? Similar to c9 tool in Cloud9.
I'm aware of the code tool, but when you run code something.php from the integrated terminal it opens a new vscode instance, which is not what I want...
You can use -r or --reuse-window command line option.
code -r something.php
just
code file_name
I tried it on Win10 and on Linux (Ubuntu)
I don't know what operating system you're using, but on MacOS you can just say open filename.ext in the integrated terminal, and it will open a new tab in the same VSCode instance, ready for you to edit.
If you are having command not found: code in macOS, use a full path to it.
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]
Open Visual Studio Code
Press CMD + SHIFT + P (this opens "Command Palette")
Type shell command
Select “Install code command in path”
Navigate to any project from the terminal, and type code .
If it didn't work, select “Uninstall code command from path” first, then reinstall it again.
I use code -r . to open the current directory in the main window.
You can use the code command from the CLI to open a file, but if you want it to open in the existing window, either use code -r <file> as mentioned in other answers (which does work for me on Ubuntu Linux), or, if -r does not work (under WSL?), make sure window.openFilesInNewWindow is either off or default in settings.json or the in VS Code settings UI, then use code <file>.
Many things can be found in open --help
A work around that worked for me on MacOS is:
open -a 'Visual Studio Code.app' something.php
in the version 1.31.0 that I have installed, on Windows 7, the only way I found to do this is to e.g. change the file associations in system so that .cproj and .cs files are opened by Visual Studio Code by default, and type "filename.cs" in Terminal to open file by that name in the same window... -r option is not working for the first call (opens a new window), but with each subsequent call that same window is correctly reused. ok can't get to open whole directories this way - it's a bit shoddy anyway. probably it would be more convenient to use an outside shell and work with "-r" option
VSCode 1.64 (Jan. 2022) comes with a new command:
Keyboard Navigable Links
Previously, link navigation in the terminal required the use of a mouse.
Now, links can be opened using only the keyboard via the following commands:
Terminal: Open Detected Link... to view all links (web, file, word)
Terminal: Open Last Web Link... ex: https://github.com/microsoft/vscode
Terminal: Open Last File Link... ex: /Users/user/repo/file.txt
Check if the last command Terminal: Open Last File Link... would help in your case.
See also "Terminal shell integration"