Can't force external terminal to open in current directory in VSCode - visual-studio-code

How can I open an external terminal in the current project directory?
I want to open a wsl session (when I invoke open external terminal) but it keeps opening in Microsoft VS Code folder
My setting is as follow:
{
"terminal.external.windowsExec": "wsl.exe"
}
I tried passing an argument
{
"terminal.external.windowsExec": "wsl.exe -d ${workspaceFolder}"
}
But vscode doesn't like that.
What am I missing?

Related

How do you select the terminal location for every terminal type in a VS Code workspace?

I am working in a VS Code workspace with multiple directories. When I open the default terminal (Powershell) it get a prompt asking which of the directory roots I want to open the terminal in.
However, if I open another terminal from the dropdown, it opens at the root location of whichever file that I am currently displaying.
Is there a setting to show this prompt for every new terminal, not just the default one? Specifically for the WSL terminal.

Launch Windows Terminal from VSCode?

I'm trying to launch the new Windows Terminal through VSCode like I have with other terminal emulators.
Previously I've used the following setting in the VSCode JSON file settings.json to launch Cmder through VSCode with ctrl+C
"terminal.external.windowsExec": "C:\\Program Files\\cmder\\Cmder.exe",
However, trying the same with the directory of the Windows Terminal directory has been unsuccessful.
"terminal.external.windowsExec": "C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_1.0.1401.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe",
I thought that the executable was wt.exe, so if I'm correct, in your settings.json, you should be using:
"terminal.external.windowsExec": "C:\\Users\\skillcap\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe",
(remember to change the user name as required).
As a side note, the executable should also have been added to your %PATH%, so you should be able to generally start it using just wt, (with an unmodified %PATHEXT% variable).

How do i open a local terminal from a remote session in VScode?

When i open my workspace in VScode i go directly into my SSH work area, which is what i want. But i want to have a split terminal with access to both my SSH-work area and a terminal for my local computer, but i cant access the local one without making an explicitly new terminal from the dropdown window. And if i try to split the new local terminal i get the error "The terminal shell CWD "/Users/asd/work/" does not exist" as if its being looked for in my SSH work directory. Is there any way of specifying the default terminal to be on my local computer? If i do so in the terminal preferences in VScode i get the CWD-error on startup instead.
This should have been resolved with microsoft/vscode-remote-release issue 1479
Both of you don't have C:\Windows\System32 on your path, I don't understand why that is.
But I will change this to not rely on the PATH.
Even if this was for Windows originally, opening a local shell, (Mac or Windows) should now be possible while having a remote session.
Wtih ctrl+shift+p or cmd+shift+p(Command Palette), you have:
Terminal: Create New Integrated Terminal (local)
Bonus, with VSCode 1.53 (Jan. 2021), there is now:
Remote layout persistence
Terminal layout is restored on remote terminal reconnection. In the video below, the terminal layout is restored when reloading VS Code and reconnecting to a Windows Subsystem for Linux (WSL) remote instance.

Opening a new terminal tab based on the current one

I've added the following keybinding in vscode to open a new terminal window:
{
"key": "cmd+t",
"command": "workbench.action.terminal.new"
}
When I execute a command like cd Desktop then run cmd+t again while still in it, the new terminal starts from zero. Is it possible for the new terminal to be based on the previous one? meaning in our case it should open a new terminal tab that runs on /Desktop instead of the root directory.
I am using bash.
Add the following to your User Settings (Menu:File > Preferences):
"terminal.integrated.cwd": "Desktop"
This will now open up in Desktop instead of having to cd into it.
I'm not sure how to change the cwd based on other open terminals per your question.Here's the full commented setting in vscode:
// An explicit start path where the terminal will be launched, this is
used as the current working directory (cwd) for the shell process.
This may be particularly useful in workspace settings if the root
directory is not a convenient cwd.
"terminal.integrated.cwd": "",

How to open file using vscode terminal?

I want to open a new tab and open a file using vscode terminal.
like open somefile.js command, so I can use ls and open file quickly.
Use code -r <file> to open the file in the last active code window
use
code -r <filename>
just remeber to install the code command to PATH. in VScode, open the command palette and type "code", you should see a Shell Command: Install code to PATH option.
I really haven't actually seen any difference between using the command without the -r flag.
If you are already in VSCode terminal (not an external OS terminal), check out the latest VSCode 1.64 (Jan. 2022) Terminal shell integration:
The terminal now features experimental opt-in shell integration which allows VS Code to gain insights on what is going on within the terminal as it was previously a black box.
When enabled using "terminal.integrated.enableShellIntegration": true, arguments to run a shell integration script will be injected into your terminal profile if possible.
The script itself mostly just injects invisible sequences into your prompt, providing us with information like where the prompt, command and command output is, what the current working directory (cwd) is for each command and the exit code of each command.
That means:
Link support relative to the cwd
Since we know the cwd for each line in the terminal buffer, we can support opening links in the terminal relative to the cwd at the location where it was activated.
Before, when a link was clicked, a quick pick would open with results from any folders containing a match for that name.
Now, the exact file match will be opened.
In a terminal with a cwd of VSCode, package.json is echoed.
Clicking on the file name will result in vscode/package.json opening.
The directory is changed to be the template-string-converter and then package.json is echoed.
Clicking on the file name will open template-string-converter/package.json.