In Visual Studio Code, how do you inject clink into the integrated terminal? - visual-studio-code

I was using clink with ConEmu for various node related tasks on windows, but now I'm trying Visual Studio code.
How do I inject clink into Visual Studio Code's integrated terminal, so that I can get real command history persistence between sessions, incremental history search, etc.?
With ConEmu I could inject clink by dropping the clink folder into a specified pickup directory.
I've tried using the path to the included clink bat file, and the clink exe in the VS Code setting terminal.integrated.shell.windows but these spawn and then close the command shell immediately.
Thanks!

I discovered that you can pass arguments to the integrated shell in Visual Studio Code. Combined with the cmd.exe /K option which Carries out the command specified by string but remains, clink can be injected.
In VS Code, go to File > Preferences > Settings or use Ctrl , and add the settings:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\path\\to\\clink\\clink_x64.exe inject"]
This is the equivalent of opening a command prompt in Windows, and running clink_x64 inject.

It is not answer for your question, but there is another trick to see cmder and text editor in one window. You can open your text editor as another tab in cmder, which I described here:
https://medium.com/#WMorkowski/protip-integrating-cmder-with-text-editor-7f08a6e76de7
from article:
Run your cmder.
Go to ‘Settings -> Startup -> Environment’
Type: set EDITOR_PATH=C:\Program Files (x86)\Microsoft VS Code\Code.exe alias editor="%EDITOR_PATH%" $1 -new_console:s50V Where
in the first line you should type path to your text editor (I was
testing it on Visual Studio Code and Sublime, but it should work with
other editors).
Save your settings
Type ‘editor’ command in command line.
Whoa! We almost finished. But in most cases you don’t want console tab
to be attached to the top of the window. You should close console tab,
and open it again, paying attention to check “New console split to
bottom” checkbox and choose the right console type. Now when you
finally set everything up, you should go to ‘Settings -> Startup’, and
check “Auto save/restore opened tabs” checkbox to save our new
workflow. Now every time you run cmder, your tabs setup will be
restored.

Expanding on my comment:
Open settings.json with:
File > Open > %APPDATA%\Code\User\settings.json
And assuming you installed clink with the magic of chocolatey:
choco install clink-maintained
Then your clink_x64.exe lives here:
C:\Program Files (x86)\clink\clink_x64.exe
And the lines you add to settings.json look like:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"C:\\Program Files (x86)\\clink\\clink_x64.exe",
"inject",
"--profile",
"~\\clink"
],
Note the addition of --profile ... this allows the history to be persistent between vscode sessions.

Related

PowerShell console in Visual Studio Code: How to copy-paste?

I cannot Copy-Paste from the Visual Studio Code console. In ISE one can copy-paste some of the output, but it does not seem to be possible in Visual Studio Code Terminal. How can I copy-paste the output from the console when running PowerShell commands? I have the PowerShell Extension.
Ctrl+C and Ctrl+V for copying / pasting work as-is in Visual Studio Code's integrated terminal.
By contrast, right-click behavior is configurable:
On Windows, the default behavior is to copy, if text is currently selected, and paste otherwise - as in regular console windows.
To get the same behavior as in the Windows PowerShell ISE, i.e. to instead show a shortcut menu, which contains Copy and Paste commands, add the following line to your settings.json file (before the closing }):
"terminal.integrated.rightClickBehavior": "default",
Alternatively, use the settings GUI (press Ctrl+,):
Note:
The screenshot was taken on macOS, where selectWord is the default setting; on Windows, it is copyPaste, with the behavior as described above.
Also note the GUI's convenient search feature: typing right click in the search field was sufficient to locate the relevant setting.

How to set Windows Terminal (UWP) as an external terminal for Visual Studio Code?

The title mostly says it all about the question.
I want to set the newest Microsoft's Windows Terminal as an external terminal in Visual Studio Code.
I found the WT's executable in C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_0.4.2382.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe. Then I entered the path into VSC in the terminal.external.windowsExec. Then tried to run my program, but VSC showed a pop-up which says "Could not find "C:\Program". Check whether the path is written right an try again."
Also I have tried to use a shortcut (literally dragged the WT tile from Start to my desktop folder), then entered its path into the setting, but it just opens the app without starting the program.
You are essentially asking VS Code to Run... a program via the Ctrl + Shift + C command.
Per the tip here, you can achieve what you are looking for by simply entering:
wt
...into the terminal.external.windowsExec section.
It might not be handling the space in the filename correctly. Try surrounding the pathname in quotes like this: "C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_0.4.2382.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe"
WT now supports the "-d" parameter to open itself in a given directory: https://github.com/microsoft/terminal/pull/4023
But VSCODE does not allow to pass arguments to an external terminal: https://github.com/microsoft/vscode/issues/58086
The workaround for this is to create a batch script somewhere called wt.bat containing:
#start wt.exe -d "."
#exit
And put it on vscode Terminal>External: Windows Exec setting.
Note that the "Windows Terminal", as external terminal, does not launch in the workspace directory (issue 90734)
Set terminal.external.windowsExec to wt
Run "Open New External Terminal" from the command palette
A new instance of Windows Terminal opens, but with the default directory, instead of ${workspaceFolder}.
So while the Windows Terminal Preview v0.9 Release allows a starting directory to be specified with -d <starting dir>, it would not work with VSCode up to 1.44 (March 2020).
This should be fixed with VSCode 1.45 (April 2020): PR 90773.
I can open it with this configuration
"terminal.external.windowsExec": "wt.exe"
My windows terminal version is 1.11.2921.0
Then I found that Windows terminal is actually wt.exe
It's in a path like this C:\Program Files\WindowsApps\************\wt.exe
Then, I add the above 'wt.exe' to the vscode configuration file

How do I get around the verified bug in Windows 1903 and launch the VSCode integrated terminal?

I just did a fresh install of Windows 10 Pro version 1903 build 18362.116 and Visual Studio Code. Now the integrated terminal only launches externally.
Pressing Ctrl + ~ results in this.
What am I missing? How do I get it to open integrated again?
EDIT
After working with VSCode team it is a verified bug. See the Github issue here. I posted the workaround as an answer here.
OK, worked through this one in VSCode repo issues.
For now, until it's fixed, turn off ConPTY integration in the User Settings.
💥💥💥
The issue now says use legacy console. To change the setting open a cmd prompt. Right click the title to bring up properties.
Then Uncheck 'Use legacy console'
To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:
Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
Check if "terminal.integrated.shell.windows" has value "C:\\Bin\\Cmder\\Cmder.exe" setting to the User Settings document on the right.
Remove this line.
Ctrl + ~ will now open integrated terminal of VSCode.
If the above solution doesn't work then can you try below values and check if it works for you:
// Command Prompt
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
// PowerShell
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
From the Command Palette (Ctrl+Shift+P), use the View: Toggle Integrated Terminal command.
Try custom shortcut:
[
{
"key": "ctrl+`",
"command": "workbench.action.terminal.toggleTerminal"
}
]
Had this problem fixed. Found the solution from the VS Code support.
for error:
Terminal exits with code 3221225786 (or similar)#
"This can happen when you have legacy console mode enabled in conhost's properties. To change this, open cmd.exe from the start menu, right-click the title bar, go to Properties and under the Options tab, uncheck Use legacy console."
source: VS Code docs

How to integrate Cmder properly in VS Code?

I would like to integrate Cmder shell into my VS Code configuration.
I'm using VS Code 64bit on Windows, and I tried to modify my settings.json file as follows, to make Cmder work as the integrated terminal:
"terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe",
I restarted my VS Code and tried to open the terminal.
At first, this error message box showed up:
Failed to copy ConEmu.xml file to backup location!
Restart Cmder as administrator.
So, I launched VS Code as administrator, which made the error message disappear; however, I noticed that VS Code opens Cmder in another separate window instead of in the terminal.
How can I run Cmder shell inside VS Code terminal?
P.S. Could this note in vs code documentation be the solution?
Tip: The integrated terminal shell is running with the permissions of VS Code. If you need to run a shell command with elevated (administrator) or different permissions, you can use platform utilities such as runas.exe within a terminal."
from: https://code.visualstudio.com/docs/editor/integrated-terminal
There is a mistake in your configuration file, the following is not valid:
"terminal.integrated.shell.windows": "C:\\Program Files\\Cmder\\Cmder.exe"
You should not be calling Cmder.exe from the VS Code, instead, you should use init.bat (from the instructions below) to integrate Cmder in VS Code.
Your issue has been already explained here over the Cmder repository.
Making Cmder work in VS Code
Make sure you're on the latest release of Cmder – download latest here
Open the settings.json configuration file, by pressing Ctrl + , (Control-Comma) to access the preferences, then click on the Edit in settings.json link
VS Code documentation explains the process in this link:
Can I use Cmder's shell with the terminal on Windows?
Yes, to use the Cmder shell in VS Code, you need to add the following settings to your settings.json file:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\cmder\\vendor\\init.bat"]
BTW, You need to replace C:\\cmder with your own installation path.
Tip: replace single backslashes (\) with double backslashes (\\).
Make sure you read the notice at the official Cmder wiki:
👉 Please note the use of cmd.exe instead of cmder.exe.
Tip: refer to here on notes about handling spaces in your path.
TL;DR: It's not recommended by the Cmder team, but you may use ^ character before spaces to handle the paths.
You don't need to restart VS Code to make this work.
Hit Ctrl + ` (Control-Tilde) to open Cmder in VS Code terminal!
You may refer to my answer here for a complete explanation of how this works.
Related
There are similar issues over the VS Code repo and here on Cmder repo as well.
Cmder 1.3.12 introduced a vscode_init.cmd script which allows VS Code tasks to work correctly with Cmder.
The documentation in VS Code, referred to in the answer above, is out of date if you're using a version of Cmder greater than 1.3.11.
The Cmder GitHub repository now has extensive documentation on how to achieve integration between Cmder and VS Code. At the time of writing this message, it is more accurate than the VS Code documentation.
This worked for me on June 22nd 2021; add these lines to the settings.json file in your user settings (for me « C:\Users\ianla\AppData\Roaming\Code\User\settings.json »):
"terminal.integrated.profiles.windows": {
"cmder": {
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": ["/K", "C:\\Users\\ianla\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.defaultProfile.windows": "cmder",
... of course, you'll need to change my « C:\Users\ianla\ » with your instalation "cmder" instalation path.
See here for more info
The following is that worked for me (version of Cmder greater than 1.3.11):
Paste \cmder directory into C:\tools
Paste in .vscode\settings.json :
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "C:\\tools\\cmder"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
],
.. and enjoy!

In Visual Studio Code, launch a Console application in an external window

I have a Console application open in VS Code. When I press Ctrl-F5, the output of my program is displayed in a DEBUG CONSOLE window, along with other text.
How do I get Visual Studio code to launch my program in a new console window?
As documented here this can be achieved using this setting:
"console": "externalTerminal"
The settings file is in the solution directory: .vscode/launch.json .
When you're just using Tasks and not Launchers, you can follow the advice here.
For me on Linux, I changed my shell command in VSCode from command to gnome-terminal -e command. That did the trick; that's all I had to do.
Note that if you do this you can get rid of the presentation option set from your task.