Use Cygwin’s Shell or Git Bash in Windows Terminal

5 minutes to read

Recently, Microsoft has made the first stable release of Windows Terminal, anew terminal program for Windows 10. Windows Terminal allows you to add and usemultiple shells, like Windows PowerShell, the old command prompt, and any shellin your Windows Subsystem for Linux (WSL) environments. It also provides waymore features and customization options than the old Windows console hostconhost.exe, which has been used for command prompt and WSL.

This post will instruct you to add other shell executables to Windows Terminal,such as the shell you installed forCygwin or GitBash if you haveGit for Windows. By doing this,you can access a Unix shell and potentially other Unix programs within WindowsTerminal without the need for WSL.

The main purpose of this post is to show you how to use your Cygwininstallation or Git Bash in Windows Terminal if you happen to have theminstalled. It is not intended to recommend Cygwin or Git Bash as WSLalternatives, though if you are interested, you may definitely try them.

The steps for Cygwin and Git Bash slightly differ, so I will first introducethe method for Cygwin, then mention what is different in the method for GitBash.

Steps for Cygwin

For the following steps, it is assumed that you have Bash installed in Cygwin.It should be possible to use other shells, but your configuration file willlook differently from what is shown here, so please pay attention to that.

  1. Download Windows Terminal fromMicrosoftStore.

    Windows Terminal in Microsoft Store

  2. Open Windows Terminal. You can find the button that opens the drop-down menuon the top, and the menu contains multiple profiles. We will create a newprofile for Cygwin’s shell.

    Drop-down menu in Windows Terminal

  3. In the drop-down menu, choose “Settings”. This will open up theconfiguration file for Windows Terminal. If you scroll down a little bit,you will see theprofiles key and thelist array under it. This is wherethe new profile will be added to.

    Windows Terminal configuration

    The basic attributes for a profile are:

    • guid: A unique identifier for the profile

    • name: The profile’s name

    • commandline: The command to start the shell used for this profile

  4. The unique identifier inguid can be any 128-bit UUID that does not repeatany existing one in the configuration file. Please notice thatyou cannotreuse the identifier for a deleted preset profile. For instance, even ifyou never use the Azure Cloud Shell and deleted its profile, you should notuse that profile’sguid for any new profile.

    After all, this should not be a problem because there are many ways to get aUUID:

    • Run theuuidgen program in Cygwin
    • Search for UUID generators online and use one of them
    • Simply use the UUID I generated for the demo, which isa1f2ceb2-795d-4f2a-81cc-723cceec49c0

    Run the “uuidgen” program in Cygwin

  5. Now, you need to know the command line used to start Cygwin’s shell.

    First, find your Cygwin installation path. By default, it isC:\cygwin64for the 64-bit version. Thebash.exe executable in a Cygwin installationshould be placed in thebin folder under Cygwin’s installation path.Therefore, the absolute path to the executable file isC:\cygwin64\bin\bash.exe by default.

    For Bash in Cygwin, you need to startbash as an interactive login shell;otherwise, you will encounter the “command not found” error when executingbasic commands likels. This is because the file/etc/profile, whichadds Cygwin’s/usr/bin and/usr/local/bin directories to thePATHenvironment variable, is not executed for non-login shells. An interactivelogin shell can be started with-i -l flags. If you are using anothershell, please confirm the way to get Cygwin’s/usr/bin and/usr/local/bin intoPATH for your shell.

    Therefore, the full command to run Bash in Cygwin isC:\cygwin64\bin\bash.exe -i -l. If you have installed Cygwin to anon-default path and/or want to use another shell, then please change thecommand accordingly.

    Finally, the configuration file accepts the forward slash/ as the pathcomponent separator, so you can replace every backslash\ in the commandwith/. For instance, the above command will be changed toC:/cygwin64/bin/bash.exe -i -l. If you want to use the backslash instead,you have to escape it by adding another backslash, causing the command tobecomeC:\\cygwin64\\bin\\bash.exe -i -l.

  6. At this point you have collected all information needed for the new profile,so it’s time to add it to the configuration file:

    {"guid":"{a1f2ceb2-795d-4f2a-81cc-723cceec49c0}","name":"Bash","commandline":"C:/cygwin64/bin/bash.exe -i -l"},

    The order of the profiles in the configuration is the same as the order inwhich they are shown in Windows Terminal. Here, because I want it to be thefirst entry, I put it before every other profile. If you are not adding itas the last profile, then don’t forget the trailing comma; otherwise, makesure the trailing comma is not there, and add a comma after the profile thatwas originally the last one.

    Adding the new profile

  7. Save the file. If your configuration file is valid, then you should now seethe new profile added to the menu. When you choose it, you should see Bashrunning in a new terminal tab.

    New profile added

    Running Bash in Windows Terminal

Steps for Git Bash

The steps to add Git Bash differ at only two places:

  • You cannot runuuidgen in Git Bash to obtain a unique identifier. However,you can still use any alternative method mentioned above to get one.

  • If you installed Git for Windows atC:\Program Files\Git, then the absolutepath to the Git Bash executable isC:\Program Files\Git\bin\bash.exe.

    Command line for Git Bash

Removing “Process Exited With Code x” Messages

Message shown for non-zero exits

If the last command you ran before quitting the shell usingexit or Ctrl-Dfinished with a non-zero exit status, you might see something like what thescreenshot shows. Sometimes this can even happen if you did not run anycommand, which is likely to be caused by a command in initialization scriptslike.bashrc.

These messages must be dismissed manually. To stop Windows Terminal fromgenerating them, add an"closeOnExit": "always" option to the new profile inthe configuration file. Don’t forget, if this option is the last line for theprofile, you need to make sure a comma exists at the end of the previous line.

Adding the option

Setting Default Windows Terminal Profile

There is adefaultProfile option in the configuration file, which allows youto choose the default shell when a new terminal window or tab is opened. Thedefault profile should be specified by itsguid.

Setting the default profile