Set the path in portable vscode installation powershell terminal - powershell

I have multiple versions of vscode installed on my system with portable mode. I start each of them via a desktop shortcut. Since they are in portable mode, their installation directories are not in the default PATH variable.
When I make a new powershell terminal window, the portable vscode directory is not on the path. I need the command "code" in the terminal window to run the same vscode version that the terminal shell is running in. In other words, if I am running a portable vscode, and I open a powershell terminal and type the command "code", I want it to run the code.exe file that is the same as the vscode I am running it in, and not a different one, and not get the "object not found" message. For various reasons I do not want to have to type the full path.
So, in essence, I want to add a directory to the path variable when vscode starts up, with that directory being the base directory of the vscode itself.

You need to set this in: File/Preferences/Settings then select Workspace, there go to: Terminal/Integrated:Cmd and there specify An explicit start path where the terminal will be launched.

Related

Cygwin terminal on VSC does not start from current directory

for some reason every time I open a new Cygwin terminaln on VSC, the working directory is set to /home/User by default. Buy I would want the working directory to be set, by default, to the path I am opening the Cygwin terminal from. I have installed the Cygwin terminal on VSC using Shell Launcher (Extension).

How does VSCode's Remote Extension open files in my local editor through its internal terminal?

I use VSCode's remote development extension fairly regularly. I can use the terminal in VS Code as if it were on my own machine, and even the code command works correctly. That is, when I'm in a remote VSCode session, I can type code path/to/some/file and it will open another editor tab with that file. The terminal session and the file being opened are on the remote machine to which I've connected.
I have VSCode installed on the remote machine, and the code executable is in my PATH. So my question is, how is this functionality implemented behind the scenes? That is, how does VSCode know that when I type code path/to/some/file it should open that file into another editor tab on my machine instead of trying to fire up VSCode on the remote machine?
Literally seconds after I wrote the question I found the answer.
If I run which code in the terminal, it doesn't resolve to the usual VSCode executable, but instead it resolves to one located at $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin/code.
If I echo $PATH I can see that $HOME/.config/bin and $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin has been appended to the beginning of the PATH env var that my bash profile generates.
I assume this means that VSCode is executing bash with a different profile script that
Sources my usual bash profile
Creates the directories above and copies some helper programs into them
Modifies my path to include these directories
I also assume that the injected code executable is communicating with my local instance of VSCode in some way, instructing it to open the file in its editor.

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

VSCode can't write to files in Bash for Windows

I've been using Bash for Windows recently (its the Ubuntu "app") and I can open VSCode from the bash command line but when I try to save any modifications I've made to the file, it just says permission denied.
I've tried creating the files directly from VS Code's terminal but in that case it doesn't print out an error message but it also doesn't save anything.
That happens because you dont have permissions to write in the system32 folder. If you run the Ubuntu application as an administrator, you'll get the permissions to write. However, you won't be really in that file, because of the way that the virtualization of files and errors might happear doing so, and I do not recommend to run the console in a privilege mode (for seccurity issues).
Fortunately, in version 1903 of Windows 10, this will change, and you'll be able to navigate the WSL folders via Windows Explorer, and for sure that issue will disappear.
Edit: the best practice, you do the work in a folder in the Windows File System, and cd to there in the WSL console. VSCode has this integrated very well, if you have an open file in VSCode you can just do New Terminal and choose a WSL terminal. The terminal will already be in the folder where you file is.

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.