How do I use Bash on Windows from the Visual Studio Code integrated terminal?

前端 未结 17 1805
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 00:28

Visual Studio Code on Windows uses PowerShell by default as the integrated terminal. If you want to use Bash from Visual Studio Code, what steps should be followed?

相关标签:
17条回答
  • 2020-11-28 00:35

    For me this is the only combination worked!

    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\git-cmd.exe",
    "terminal.integrated.shellArgs.windows": [
      "--command=usr/bin/bash.exe",
      "-l",
      "-i"
    ]
    

    With git-bash.exe as the ...shell.windows, every time the bash was opening outside VS!!

    Thank God it worked finally!! Else, I was planning to wipe out VS completely and reinstall it (making me to reinstall all my extensions and redo my customizations!)

    0 讨论(0)
  • 2020-11-28 00:36

    This answer is similar to the top voted answer, but with an important distinction: a lot of the previous answers on this question focus on running Git Bash while my answer focuses on running WSL Bash.

    1. Enable Windows Subsystem for Linux on your Windows 10 machine.

    2. Open Visual Studio Code and press and hold Ctrl + ` to open the terminal.

    3. Open the command palette using Ctrl + Shift + P.

    4. Type - Select Default Shell.

    5. Select WSL Bash (NOT Git Bash) from the options.

    1. Click on the + icon in the terminal window. The new terminal now will be a WSL Bash terminal!
    0 讨论(0)
  • 2020-11-28 00:37

    Press and hold Ctrl + ` to open the terminal. Inside the terminal, type bash to use Git Bash in the terminal. Note: Make sure you have Git Bash installed on your machine.

    If you wish to use PowerShell again, just type powershell in the terminal. To use the Windows command line, type cmd in the terminal.

    The setting you choose will be used as your default.

    0 讨论(0)
  • 2020-11-28 00:37

    This, at least for me, will make Visual Studio Code open a new Bash window as an external terminal.

    If you want the integrated environment you need to point to the sh.exe file inside the bin folder of your Git installation.

    So the configuration should say C:\\<my-git-install>\\bin\\sh.exe.

    0 讨论(0)
  • 2020-11-28 00:37

    Add the Git\bin directory to the Path environment variable. The directory is %ProgramFiles%\Git\bin by default. By this way you can access Git Bash with simply typing bash in every terminal including the integrated terminal of Visual Studio Code.

    How to set the path and environment variables in Windows

    0 讨论(0)
  • 2020-11-28 00:38

    I tried the above answers as of vscode 1.42.1 and they worked inasmuch as to get me a git bash terminal. So, bottom line this setting works just for opening a bash shell from terminal:

    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
    

    However it has the unwanted side effect of also being the shell used to build things and that breaks the MS C++ chain because the \ character used for path separator is understood by bash as an escape character. The complete fix for me then required me to add this extra variable, setting it to powershell:

    "terminal.integrated.automationShell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
    

    Now, I can have my bash terminal and Ctrl-Shift-B or F5 work without problems.

    Oh, and as other posters mentioned, the source for this information is VSCode's documentation.

    0 讨论(0)
提交回复
热议问题