Git Bash wit Visual Studio Code: how to set permanent PATH - visual-studio-code

I'm using VSCode with git bash and minGW. Every time I restart VSCode the PATH is reset to default. I add my path to mingw with export PATH=$PATH:/c/mingw/bin
How can be permanent changed? I created .bashrc in my code folder but it doesn't works
Thanks

Search for "path" in the windows control panel. you can then "edit the system environment variables". You can edit it in to the system path.
You will need to restart VSCode after you change it, then it will be there every time..
Note that in the future this may cause problems if you have a separate version of something using mingw dlls.

Related

vscode can't find buildifier on remote instance

I'm bumping into a weird vscode issue. I use vscode to ssh into my EC2 instance. I primarily use bazel as the dependency management and build system for development. I installed buildifier, and included in my path variable however vscode still doesn't detect it. If I type buildifier <some bazel build file> in the terminal in vscode, it works perfectly, but if I try to use the formatting shortcut on the file using vscode, it doesn't. I went to the extension settings, and in the remote settings I explicitly put buildifier as the executable command. Still not working. Any help would be appreciated.
Thanks!
It's likely that the path you've set is set somewhere that the vscode remote server isn't looking. So it might be in your shell path but not the vscode remote servers path when it starts up.
As a workaround find the full path of buildifier e.g.
whereis buildifier
Then simply copy past the full path of buildifier into your settings under the Bazel: Buildifier Executable section.

Visual Studio Code - "Shell Command: Install 'code' command in PATH command."

Consider:
I just started with Angular. I installed angular/cli and added a project.
Now I want to use Visual Studio Code.
I open the Command Palette (Ctrl + Shift + P) and type 'shell command' to find the shell command: Install 'code' command in PATH command.
But I get this message
"No commands matching"
Why does it not exist?
With Windows it is installed by default so you don't need to add path. Just run " code . " in cmd and it will work fine
If in Visual Studio Code doesn't appear that option and the installation didn't add to the path directly, you can add the Visual Studio Code bin folder manually to the path and it starts to work.
Go to the Enviroment Variables and edit the Path user variable.
Inside of it, add a new variable with the current bin path of your Visual Studio Code installation.
Mine, for example, is "C:\Users\Inazio\AppData\Local\Programs\Microsoft VS Code\bin"
After that, you can start to use the code command in your OS
I had this same problem. Long story short, I uninstalled VS Code, re-downloaded the installer package and ran that. Sure enough, one of the install screens has a checkbox option to add to the PATH variable and this option is unchecked by default.
Checked the box, finished the install, works fine.
Of course it's perfectly valid to modify the PATH variable after install, but I think it's important to clarify that (at least version 1.23.0) does not update PATH by default. Most of the threads I looked at says it does.
I fixed this just adding "C:\Users\myUser\AppData\Local\Programs\Microsoft VS Code\Code.exe" (where myUser is your windows user) without "" to system path.
same effect than " Shell Command: Install ‘code’ command in PATH ".
This works for me
For Windows users
Open Environment Variables
System > Advance system settings > Advanced tab > environment variables on system variables click on Path and click Edit and add new Path named
"C:\Users\Your-Username\AppData\Local\Programs\Microsoft VS Code\bin"
For window users follow steps below and add new Path, after doing so restart your terminal you will get code command on your terminal
If you already have Visual Code into Windows path and in a terminal you put "code ." and Visual Code starts, what happens is that the command "code" is not linked to the path in wsl2.
All you have to do is run the following command changing your user:
sudo ln -s /mnt/c/Users/CHANGE_USER/AppData/Local/Programs/Microsoft
VS\ Code/bin/code /usr/bin/code
This works on Ubuntu and Debian.
it is already installed on Windows. You just have to make cmd path where the project created (e.g C:\WINDOWS\system32> cd C:\WINDOWS\system32\hello-world), then run the the comamnd "code ." like this (C:\Windows\System32\hello-world>code .)
I got this from VS Code documentation
the path has been set automatically when installing VS.But i noticed a difference between "code." and "code ." Can you see the difference? The second has space in between the code and the dot. Try that.
I was having the same exact problem and when i checked my PATH variable it said that the path was something\something\Microsoft VS Code . then i remembered my folder's name was Visual Studio Code.After I renamed it back everything works.
Go to Extensions and install Shell. On newer versions you can just type in Code . in CMD and it will pop-up.
Just open your command prompt and type:
cd hello-world
hello-world is the project name don't forget to change it then click (enter) and type
code .
Visual Code already have internal terminal window
Use the Ctrl+` keyboard shortcut with the backtick character.
Its supports all Ubuntu terminal commands

Set global $PATH environment variable in VS Code

I'm defining a custom $PATH environment variable in my ~/.bash_profile (on a Mac), like so:
PATH="$HOME/.cargo/bin:$PATH:$HOME/bin"
However, VS Code of course does not run my .bash_profile, so it does not have my custom paths. In fact, if I Toggle Developer Tools and check process.env.PATH, it doesn't even seem to have /usr/local/bin.
How do I globally set the $PATH environment variable in VS Code?
(I want to set it globally, not per project or per task, since I'm maintaining a lot of small packages.)
If you only need the $PATH to be set in the integrated terminal, you can use VS Code's terminal.integrated.env.<platform> variable (added in version 1.15). Press Cmd+Shift+P (or Ctrl+Shift+P) and search for "Preferences: Open Settings (JSON)". Then add the following entry to the settings file:
"terminal.integrated.env.osx": {
"PATH": "...:/usr/bin:/bin:..."
}
(Replace .osx with .linux or .windows as needed.)
To see your system's $PATH, type echo "$PATH" in Terminal.app, and copy and paste it into the settings snippet above.
As for having the $PATH available everwhere in VS Code, so that it will
be used by extensions that call binaries, the only workaround I've found so far is this:
Configure your shell (bash by default) to have the $PATH you want. For example, my ~/.bash_profile has the following line:
PATH="$PATH:$HOME/bin"
In VS Code, press ⇧⌘P and type install 'code' command if you haven't done so before.
Quit VS Code.
Launch VS Code not by clicking the icon in the dock or in Launchpad, but by opening Terminal.app and typing code. Your newly set path will be active in VS Code until you quit it.
If VS Code restarts, for example due to an upgrade, the $PATH will reset to the system default. In that case, quit VS Code and re-launch it by typing code.
Update: VS Code on Mac and Linux now apparently tries to automatically resolve the shell environment when it is started by clicking the icon (rather than via code). It does this by temporarily starting a shell and reading the environment variables. I haven't tested this though.
In:
> Preferences: Open Settings (JSON)
add to the JSON file:
"terminal.integrated.env.windows": {
"PATH": "${env:PATH}"
},
-> terminal.integrated.env should end with .osx, .linux or .windows depending on your OS.
In order to check if it works execute in your VS Code Terminal:
# For PowerShell
echo $env:PATH
# For bash
echo "$PATH"
I am using vscode on macos for C/C++ development in conjunction with CMake.
The vscode extension CMake Tools allows to manipulate environment variables via the configuration properties cmake.configureEnvironment, cmake.buildEnvironment and cmake.environment (acting respectively on the CMake configuration phase, the build phase and both - see docs).
Then you can extend your system PATH with custom paths by adding the following snippet to your user or project settings.json:
"cmake.environment": {
"PATH": "~/.myTool/bin:${env:PATH}"
},
Visual Studio Code is the problem.
No matter how you set your PATH variable in the shell, there are cases where Visual Studio Code will not inherit your PATH setting. If you're using an application launcher like LaunchBar to start Visual Studio Code, your PATH variable will not be inherited.
Here is a system-wide fix:
In the /etc/paths.d directory, create a file with your Unix username. In that file, place the additional paths that Visual Studio Code needs to work. In my case, this is the contents of my /etc/paths.d file:
/usr/ucb
/opt/local/bin
/opt/local/sbin
~/go/bin
Note: Your /etc/paths.d file will be processed system-wide. Since most systems are single-user, this shouldn't be a problem for most developers.
Since this is the top Google search result for variants of "VS Code path", I will add my answer here.
I'm running Linux and my problem was that VS Code couldn't find some executable needed to build my project. I was running VS Code from the quick launcher (ALT+F2), and not from a Terminal. I tried modifying the PATH variable in many different places, but I couldn't seem to get it right.
In the end, placing the right PATH inside of ~/.zshenv is what worked. It's because .zshenv is the only file that gets sourced for non-interactive shell command execution like from inside of VS Code (more detailed explanation here https://unix.stackexchange.com/questions/71253/what-should-shouldnt-go-in-zshenv-zshrc-zlogin-zprofile-zlogout )
This was even easier to fix than the above answers suggested.
Open VSCode Settings (Ctrl + ,) and search for terminal.defaultProfile.
I updated my Terminal > Integrated > Default Profile: Windows.
It was set to null by default. As soon as I changed it to PowerShell and restarted the terminal, it picked up my system's path variables!
What did the trick in my case (Linux Mint 19.3 Cinnamon, VS code installed via snap) was to put my appended PATH in ~/.profile . Since this file is read at the beginning of a user session, don't forget to logout/login or reboot after editing this file.
I'm working with ubuntu 18.04. I had a similar problem, my enviroment variables were defined and the terminal knows the $PATH but when I tried to debug with golang, go libraries were not found in $PATH variable.
So, to solve it I uninstall the default version from ubuntu software and install manually using the following instructions:
https://code.visualstudio.com/docs/setup/linux
It works for me.
As of VS Code v1.63.2, you can proceed with Ctrl + Shift + P and then type Open Settings (JSON), and simply add the following line.
"terminal.integrated.inheritEnv": true
In my case the code was already there, but set to false. After changing it, everything was fine.
Getting Code to load your existing ~/.bash_profile would be best. I think the docs here are the relevant reference:
https://code.visualstudio.com/docs/editor/integrated-terminal#_linux-os-x
Typically $SHELL is your primary shell on Unix-like systems so you
probably won't want to change the shell. You can pass arguments to the
shell when it is launched.
For example, to enable running bash as a login shell (which runs
.bash_profile), pass in the -l argument (with double quotes):
// Linux "terminal.integrated.shellArgs.linux": ["-l"]
// OS X "terminal.integrated.shellArgs.osx": ["-l"]
Although, it looks like that setting is the default on my current VS Code (OS X) setup. Integrated terminal is running my ~/.bash_profile without any changes to the configuration. Perhaps try adding echo Executing .bash_profile... to test if it's running when a new terminal is opened in Code.
Add the following to your ~/.bash_profile:
launchctl setenv PATH $HOME/.cargo/bin:$PATH:$HOME/bin
Or run a Bash script when needed, e.g.:
#!/bin/bash
set -Eeuxo pipefail
proj_path=$( cd $( dirname ${BASH_SOURCE[0]} ) && pwd )
launchctl setenv PATH $proj_path/bin:${PATH:-}
For me it's resolved by editing the .desktop file.
Originally I have
Exec=/usr/bin/code-oss --unity-launch %F
. Just changed to
Exec=zsh -c "source ~/.zshrc && /usr/bin/code-oss --unity-launch %F"
since I use zsh, instead of bash. But if you have the same problem with bash, simply replace zsh with bash. And shortcuts from your desktop environment should be fixed.

VS Code Error: spawn git ENOENT

I get the error Error: spawn git ENOENT when I try to view git history using https://github.com/DonJayamanne/gitHistoryVSCode on VS Code.. I'm very new to VS Code and github. I tried googling for solutions but I only found links about node.js which I don't understand at all..
We need to install Git to use the Git History (git log) extension in VS Code.
Otherwise we will see this when running git log.
If you have already installed Git, then make sure that it is available from the shell, for example by typing git --version.
Once you have Git installed properly, you will see this when running git log.
That means you need to set environment variable in system for git. After you set it well, the issue will disapper.
If your OS is Windows:
Try typing "git --version" in the system command line (do not use git bash by mistake). If you cannot see the version, it indicates that git is not added to the environment variables.
For example, my Git is installed on the disk "C:\", I need to add "C:\Program Files\Git" to the path of the environment variables.
Method 1:
Steps:
Edit environment variables -> System Variables
Edit Path,
add
;C:\Program Files\Git\bin\git.exe;C:\Program Files\Git\cmd;
to current value of Path (remove the beginning ; if redundant).
You need to adjust this file path according to your actual directory where git is installed.
Then restart your command line, and then try typing "git --version" again. If you can see python version now, try your vs code again, the issue you metioned will disappear.
Another method:
Reinstall your visual studio code with checking "Add to PATH (available after restart)".
I had the same issue on MacOS (running VS Cod 1.26.1). With difference to other info that I had found, I worked only after setting:
"git.path": "/usr/local/bin/git"
No success setting the path to null or any other.
I just got this error while trying to use the Worktrees tab from the GitLens extension. With git worktree list I found out I had some prunable worktrees, so it worked again after I ran this:
git worktree prune
In Mac OS you have to modify your settings.json. For me currently located in Users//Library/Application Support/Code/user/settings.json
or what it is the same ~/Library/Application Support/Code/user/settings.json
There set "git.path": "/usr/local/bin/git",
You can achieve the same inside Visual Studio Code going to the "Settings" Gear Icon > Settings Then search for git. Under Extensions go to Git and look for Path Click on Edit in settings.json
It will open the same file inside the editor
See the image for VSCODE
install git, and run git init
If you are getting this error from a React app created using Create React App, i.g. create-react-app nameOfYourApp, you need to setup CircleCI environment. More info here https://facebook.github.io/create-react-app/docs/running-tests
On your own environment
Windows (cmd.exe)
set CI=true&&npm test
set CI=true&&npm run build
(Note: the lack of whitespace is intentional.)
Windows (Powershell)
($env:CI = "true") -and (npm test)
($env:CI = "true") -and (npm run build)
Linux, macOS (Bash)
CI=true npm test
CI=true npm run build

How to call VS Code Editor from terminal / command line

The question says it all.
How can I open VS Code editor from
windows cmd
linux and mac terminal
e.g. for notepad++ I write
> start notepad++ test.txt
By the way, the editor is awesome (cross-platform)! Thank you Nadella!
You can download it from microsoft
To open a file or directory use the command:
code /path/to/file/or/directory/you/want/to/open
For macOS users, it needs to be installed manually:
Launch VS Code.
Command + Shift + P to open the Command Palette.
Type shell command, to find the Shell Command: Install 'code' command in PATH and select to install it.
Restart your terminal.
Per the docs:
Mac OS X
Download Visual Studio Code for Mac OS X.
Double-click on VSCode-osx.zip to expand the contents.
Drag Visual Studio Code.app to the Applications folder, making it available in the Launchpad.
Add VS Code to your Dock by right-clicking on the icon and choosing Options, Keep in Dock.
Tip: If you want to run VS Code from the terminal, append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Now, you can simply type code . in any folder to start editing files
in that folder.
Tip: You can also add it to VS Code Insiders build by changing "com.microsoft.VSCodeInsiders". Also if you don't to type the whole word code, just change it to c.
Linux
Download Visual Studio Code for Linux.
Make a new folder and extract VSCode-linux-x64.zip inside that folder.
Double click on Code to run Visual Studio Code.
Tip: If you want to run VS Code from the terminal, create the following link substituting /path/to/vscode/Code with the absolute
path to the Code executable
sudo ln -s /path/to/vscode/Code /usr/local/bin/code
Now, you can simply type code . in any folder to start editing files
in that folder.
VS Code is a must have code editor for 2018
For Windows 10 users a lot is possible, the same way the Mac OS users type code . .
Look for you VS Code \bin folder path e.g C:\Program Files\Microsoft VS Code\bin . The bin folder includes a file called code.cmd .
If you are not sure about what is your path, type where code.cmd, and then, copy it without the \code.cmd after the ...\bin.
Follow the steps below and be proud of the OS you use.
Search for "Advanced System Setting" from Start.
Click on Environment Variables.
On System Variables choose "path" from Variable tab and click on Edit.
Click on New on the right side of the popup window.
Copy your path from the Explorer's breadcrumb path and paste it into the new opened path in step 4, example:- C:\Program Files\Microsoft VS Code\bin.
Click Ok on all the open windows to confirm changes and restart your cmd .
Go to your cmd and navigate to you working directory on server and type code . .
C:>cd wamp64\www\react-app> code . to open with VS Code on Windows.
Visual Studio Code also includes a command prompt (terminal) window and you can open one or more of them with:
Ctrl + ` on your keyboard.
Hope this helps some one like it did to many of us.
You can also run VS Code from the terminal by typing code after adding it to the path:
Launch VS Code.
Open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install code command in PATH command.
Mac shell commands
Restart the terminal for the new $PATH value to take effect. You'll be able to type code . in any folder to start editing files in that folder.
For VS Code Insiders Windows users (vs code doc):
Add the directory "C:\Program Files (x86)\Microsoft VS Code Insiders\bin"
at %PATH% environmental variable.
then go to the folder that you want to open with vs code and type:
code-insders .
Sometimes setting path from VS Code command palette does not work
Instead manually add your VS Code to your path:
Run in terminal
sudo nano /etc/paths
Go to the bottom of the file, and enter the path you wish to add
Hit control-x to quit. Enter “Y” to save the modified buffer.
Restart your terminal and to test echo $PATH. You should something similar
~ echo $PATH /Users/shashank/.nvm/versions/node/v8.9.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
Next time, you navigate to your project folder from terminal
Enter:
code .
or
code /path/to/project
Source
In the case of Linux and Mac, you want to navigate to the directory that you extracted the VSCode files using the 'cd' command. For example:
cd ~/Downloads/VSCode
Then you start the application by running..
./Code
'Code' being the name of the executable.
If you have root access on the machine, you can configure the system to allow you to start VSCode from anywhere by linking it to /usr/bin, where links to executables are often stored.
sudo ln -s /path/to/VSCode/folder/Code /usr/bin/Code
You can now launch VSCode from anywhere by typing:
Code
For command line heads you can also run
sudo ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code
this will do the exact same thing as the Shell Command: Install 'code' command in PATH command feature in VSCode.
When installing on Windows, you will be prompted to add VS Code to your PATH.
I was trying to figure out how to open files with VS Code from the command line and I already had the capability - I just forgot I had already added it. You might already have it installed - check by navigating to a folder you want to open and running the command code . to open that folder.
In linux if you use code . it will open VS Code in the folder the terminal was in.
Using code . Filename.cs it will open in folder and open said file.
For linux Debian the below can be done
$ export PATH=$PATH:/usr/share/code
Then run it
$ code
$ code file.py
$ code workingdir
Open command line and type:
cd your_folder_path
code.cmd .
or
code.cmd your_folder_path
It will open your folder in Visual Studio Code.
Make Sure, you are inside the correct folder after executing "cd your_folder_path" command.
On Windows you can add the following path to the system environment variables.
C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin
This works for Windows:
CMD> start vscode://file/o:/git/libzmq/builds/msvc/vs2017/libzmq.sln
But if the filepath has spaces, normally one would add double quotes around it, like this:
CMD> start "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln"
But this messes up with start, which can take a double-quoted title, so it will create a window with this name as the title and not open the project.
CMD> start "title" "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln"
typing "code" in dos command prompt worked for me
On Ubuntu the flatpak version seemed broken. I uninstalled it and downloaded the deb package right from Microsoft.
I use the following command to load a project quickly (in linux)
cd into the project cd /project
run command code pwd
similar steps can be used in other Os too.
In linux terminal you can just type:
$ code run
Windows:
Add code CLI path in a system environment variable.
in windows default code cli path is (username is you pc username)C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin
Then you can check it like this by taking your project folder and open new cmd and type code .
Step 1: create a .bat file with the name you want e.g vscode.bat
Step 2: Write your path to Visual Studio Code
Step 3: Save it in C:\Windows\System32 directory
**
C:
cd Users\Bino\AppData\Local\Programs\Microsoft VS Code
Code.exe**
Step 4: You can call visual studio code from any where by typing "vscode" which is the name of your bat file
This will work. This is your directory name "Directory_Name"
sudo code --user-data-dir="Directory_Name"
Other easyway to do it on mac is :go to Command Palette[ Shift ⇧+ Command (⌘)+P] and type :Shell Command: Install 'code' command in PATH
once installed: Shell command 'code' successfully installed in PATH.
Then you can use code from the terminal as well.
If you install VS CODE using snap. You will need to add /snap/bin in your PATH environment variable.
so - open your .bashrc or .zshrc
and add :/snap/bin in your PATH environment variable
reload terminal,
and than code comand will start it
A simple way is to go to your Project where you want to open it and type
code.cmd D:\PathTo\yourProject\MyProject
That's it. It will open your project in Visual Studio Code.
Delete old virtual environment and create a fresh virtual environment.
In a way I am reticent to add to the long list of answers. However, I searched this page for the word "portable" and came up empty. (And I did a full Stack Overflow search and also found nothing.) So I want to add this very specific answer for potential future searchers.
This answer is for if you installed VS Code in Portable Mode on Windows 10.
"Portable Mode" refers to what is described on the official VS Code web pages, which as of 21 January 2021 are found here: https://code.visualstudio.com. It does not mean the Visual Studio Code Portable project started/run by Gareth Flowers, or any similar project. (I am not saying anything bad about this or other projects - I have neither used nor evaluated.) If you are using one of those projects, you need to check with that project documentation/community - although this might work.
"Installing" VS Code in Portable Mode is downloading a .zip archive and extracting it locally wherever you want your VS Code "installation" to live. There is no actual installation or setup that is run, so there is no automatic adding of the code command to your PATH.
Answer
After extracting the Portable Mode VS Code files to the location of your choice, there should be a bin folder in that location. Copy the full path of that bin folder and add it to your System or User (your choice) PATH variable.
You should then be able to use the code command from PowerShell or CMD.
In linux you need to check first what is the name you your vscode binary file
When you get the binary file name check where it is by using this command :
whereis your_file_name
Go to the / (root) and go to bin and rename file with any name what you want to call it.
To rename : mv your_file_name your_changed_name
Now you can access vscode from any where in terminal
This works on Debian based Os definitely