Change path for git bash terminal in VSCode - visual-studio-code

When I use a git bash terminal in VSCode, I get the error
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
That's because the default path for git bash is C:\Program Files... (see pic bellow)
I tried to install a portable Git to the folder without spaces and then in VSCode to change a git path, but it didn't change the path for git bash. Also, I tried to add the "path" parameter in a settings.json, but it looks like the predefined terminals use the default path, not the custom ones defined in the settings.
"Git Bash": {
"path": "C:\\Windows\\SysWOW64\\Git\\bin\\Bash.exe"
}
How can I set the custom path for the git bash terminal?
Terminal path pic

To change the installation path of Git Bash, try renaming "Git Bash" to "Git_Bash". VS Code seems to prefer the default path over any customized path for Git Bash due to a bug. I installed Git under D:\Program Files, so I did this:
{
"terminal.integrated.defaultProfile.windows": "Git_Bash",
"terminal.integrated.profiles.windows": {
"Git_Bash": {
"path": "D:\\Program Files\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
}
}

In my case what helped me was to change git.path in settings.json
Press CTRL+SHIFT+P
Type Open Settings
Choose Preferences: Open User
Settings (JSON)
Change git.path parameter to that
"git.path": "C:\\PROGRA~1\\Git\\bin\\git.exe",
The explanation found here:
The space in folder name breaks the prompt so in your settings.json
file make sure you update the path "Program Files" to simply
"PROGRA~1" instead

Related

Git bash is installed and integrated but I don't see it in the terminal list of vs code

All other terminals are visible enter image description herein the list like command prompt, etc. But, Git bash is not showing up. I am worried If I have installed and integrated Git properly. I am sharing the settings.json. Please, let me know where I am wrong or I can share more info
Open you settings.json file and add the following at last.
"terminal.integrated.profiles.windows":{"GIT BASH ADDED ":{"path":"C:\\Program Files\\Git\\git-bash.exe"}, },
"terminal.integrated.defaultProfile.windows": "Git Bash"
Remember to add the path of your git-bash.exe correctly (wherever you have installed it).
see the screenshot for you reference.

How to run streamlit multi-command in VS Code regardless of default terminal

I have the Multi-command extension installed on VS Code and use it to launch Streamlit apps using this configuration in settings.json which is run via a keyboard shortcut:
"multiCommand.commands": [
{
"command": "multiCommand.streamlitActiveFile",
"label": "Streamlit: Run Active File",
"description": "Streamlit run active file in active terminal",
"sequence": [
"workbench.action.terminal.focus",
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "streamlit run ${relativeFile}\u000D"
}
}
]
}
]
This has worked fine thus far while I have been using the standard command prompt on a Windows machine. Now I've changed to using Git Bash as my default terminal, and the command above fails because the relative file path is passed as a Windows path with backslashes, and Git Bash can't parse that:
$ streamlit run visuals\streamlit\time_plot.py
Usage: streamlit run [OPTIONS] TARGET [ARGS]...
Try 'streamlit run --help' for help.
Error: Invalid value: File does not exist: visualsstreamlittime_plot.py
In short, the backslashes are ignored and the path becomes a single file name instead. I'd like some way to be able to launch Streamlit apps using a multi-command via a keyboard shortcut, and I'm open to either of these solutions, or something else I haven't considered:
Send a relative file path that can be parsed correctly regardless of which terminal is the default terminal.
Launch a Windows command prompt even when Git Bash is the default terminal, and activate the Streamlit app there.
Change the working directory to the directory containing the streamlit file (again regardless of which terminal is the default terminal) and launch the file there without having to give a path.

How to set from command line "select interpreter" of "ms-python.python"?

I have installed this extension.
Is there any way I can set the select interpreter path from command line?
You can set it through the file settings.json either in vscode user domain or in a vscode workspace .vscode path.
{
//...
"python.defaultInterpreterPath": "python" // the default path
}
If you want you could modify settings.json through commandline.

Git-Bash in Visual Studio Code from the D drive

I am trying to use Git Bash as a terminal in Visual Studio Code, however I am not able to find it in the terminal profiles. The option for Git Bash doesn't appear in the available terminals. I have installed Bash already. However I did it in the D drive. Is there a way to make git-bash available to choose as a terminal or even make it the default one from the D drive?
You can create your own profile in the setting.json file and set the default terminal profile to it, like so (for Windows):
"terminal.integrated.profiles.windows": {
"My Git Bash":{
"path": "D:\\GitbashLocation\\git-bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "My Git Bash",
Note that you can name your profile whatever you want. You may also need to restart Visual Studio Code after defining your profile so it detects it when you specify it in the terminal.integrated.defaultProfile.windows setting.
I was also struggling with the same but finally got it fixed with thanks to the final bit of help needed from #Timothy G's answer, with the help of other posts here on stack as well.
Let me just post a step-by-step solution adding to the #Timothy G's answer below, JIC if you're still struggling with it and also for future visitors.
Note: I'm using VS Code Insiders build (Version: 1.64.0-insider(user setup)) on Windows, but should work for other builds as well.
Since you have already downloaded git bash, ignore the 1st step.
Download git bash from the https://git-scm.com/download/win.
Open VS Code ⟹ File ⟹ Preferences ⟹ Settings. (Ctrl + ,).
There will be a search bar on top.
Search for terminal.integrated.profiles.windows.
A result will come up that would look like this
Terminal › Integrated › Profiles: Windows
The Windows profiles to present when creating a new terminal via the terminal dropdown. Use the source property to automatically detect the shell's location. Or set the path property manually with an optional args.
Set an existing profile to null to hide the profile from the list, for example: "Ubuntu-20.04 (WSL)": null.
Edit in settings.json
Click on Edit in settings.json.
Then another window will pop up next to the Settings tab called settings.json
Copy and paste this inside the settings.json. Remember to set the “path” to your git bash.exe in the bin folder
You can remove the first two lines if you don't need it and do Ctrl + S to save the JSON settings.
{
"workbench.colorTheme": "Default Dark+",
"files.autoSave": "afterDelay",
"terminal.integrated.profiles.windows": {
"My Git Bash":{
"path": "I:\\Projects\\git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "My Git Bash",
}
After adding the above, select the “Settings” tab again and search for terminal.integrated.defaultProfile.windows
Then you'll be presented with a terminal feature like this with a drop-down.
Terminal › Integrated › Default Profile: Windows
The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.
Under the drop-down, select the profile My Git Bash then you're
all set.
Then got to ⟹ View ⟹ Terminal. (Ctrl + `)
It should now show up with the bash terminal. If it doesn't, restart VSC and it'll work for sure.
In order to make Timothy G.'s answer work, first, add the new profile as described in the VSCode documentation:
Step 1: "To create a new profile, run the Terminal: Select Default Profile command and activate the configure button on the right side of the shell to base it on. This will add a new entry to your settings that can be tweaked manually in your settings.json file."
https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles
Type in a new name in the input box after you click the "configure" button. This will create a new profile in settings.json with your new name cloned from an existing profile (against which you clicked the "configure" button).
Step 2: Go to the settings.json file. You will see the profile with your new name added there. Update it with Timothy G's settings. Here is how mine looks like:
{
"My Git Bash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
"terminal.integrated.defaultProfile.windows": "My Git Bash"
}
Step 3: Save and restart VSCode. The next time the terminal will open with Git Bash.

Change default working directory for VS Code terminal

Is it possible to change the working directory for new integrated terminal windows in Visual Studio Code?
I have opened the folder /path/to/project in Code, so when I open a new terminal windows, it starts in that folder. I would like the terminal to open in /path/to/project/app so that I don't have to cd to that folder every time. Is it possible to configure this in settings.json?
It turns out this was fairly easy to find in the documentation at https://code.visualstudio.com/docs/getstarted/settings.
The setting that controls this is
// 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": "",
This can be added to settings.json in the .vscode folder. Absolute and relative paths are supported, so
"terminal.integrated.cwd": "app"
and
"terminal.integrated.cwd": "/path/to/project/app"
will both work.
if you are changing your directory in your .bashrc or .zshrc file to your home directory (cd ~/ or cd $HOME/) then your vscode console will use the directory that you have specified.
Bellow is a little code you can use in your .bashrc or .zshrc to address this:
if [ "$NAME" != "Code ]; then
cd ~
else
cd $OLDPWD
fi