Terminal: Upon installation, add a Git Bash profile, if Git for Windows is present

Created on 22 Jun 2019  Â·  14Comments  Â·  Source: microsoft/terminal

Summary of the new feature/enhancement

When installing the terminal for the first time, it would be nice if a profile for Bash from Git for Windows would be automatically provided if Git for Windows is installed.

Proposed technical implementation details (optional)

Auto-detect via installer registry keys whether Git for Windows in installed, and if so, add an entry to profiles.json to run Bash from Git for Windows in the terminal app.

Area-Extensibility Area-Settings Help Wanted Issue-Task Product-Terminal

Most helpful comment

Specifically, use this JSON fragment to open Git Bash (if it's installed in the default location):

    "commandline" : "C:\\Program Files\\Git\\bin\\bash.exe",
    "icon" : "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico",
    "name" : "Git Bash",
    "startingDirectory" : "%HOMEDRIVE%%HOMEPATH%"

All 14 comments

Tried to manually add but it opens in a separate window. Not sure if is compatible

If you are launching “mintty,” or if git bash is using “mintty,” it will launch in a separate window. We can’t fix that: they’ve chosen to launch their own terminal emulator.

The "trick" is that you must no run git-bash.exe (or git-cmd.exe) from the Git for Windows installation directory, as these hard-code to use mintty (or conhost) as the terminal, but you should use bin\bash.exe which just is the plain shell interpreter.

Specifically, use this JSON fragment to open Git Bash (if it's installed in the default location):

    "commandline" : "C:\\Program Files\\Git\\bin\\bash.exe",
    "icon" : "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico",
    "name" : "Git Bash",
    "startingDirectory" : "%HOMEDRIVE%%HOMEPATH%"

Tried to manually add but it opens in a separate window. Not sure if is compatible

I also tried and see the same... it opens the git-bash.exe as a separate window

see the same

Good thing somebody responded with the actual fix :)

Issue extension and suggested name: Scan installed shell interpreters on Terminal first run/install and initial profiles.json generation

Scanning PATH for known shells at their default install locations. If a shell is present, add it (along with any custom fixes such as the bin\bash.exe for Git for Windows. Essentially an enhancement for the function that scans names of configured WSL distros.
Fix PowerShell Core: on initial profiles.json generation, scan installed versions and name accordingly (PowerShell Core <version>). Can get version from exe properties. Add icons to ms-appx://ProfileIcons (pscore has some in it's assets folder. If detecting third-party interpreters, can opt to try get from exe or ico if present in shell path). So that if you have both PSCore6 and PSCore7.0.0-preview or any other version installed prior to running Terminal for the first time, all PowerShells get registered on profiles.json.
Also to fix initial detection of cmd

Ideally (for this manually edited my profiles.json, but the intent is to have shells automatically detected) :

screenshot 2019-06-22 003

Scanning PATH for known shells at their default install locations.

Note that, strictly speaking, scanning PATH is not enough, as esp. Git for Windows often is not in the system PATH. Instead, Git for Windows (or shells in general) should be discovered by looking at the registry like I had proposed above. At the concrete example of Git for Windows the registry key to look at is InstallLocation at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1.

Tried to manually add but it opens in a separate window. Not sure if is compatible

I also tried and see the same... it opens the git-bash.exe as a separate window

use bin\bash.exe instead of git-bash.exe

We've got dynamic profile generation on our radar; #754 is in spec review #1258

I'm actually going to re-open this to make sure that it gets done once #754 is complete.

Here is a code snippet of my config file that has it loading in the terminal. Thanks to everyone who contributed to the solution. I'm using a custom icon, so it won't be in your path.

      {
        "acrylicOpacity": 0.5,
        "background": "#012456",
        "closeOnExit": true,
        "colorScheme": "Solarized Dark",
        "commandline": "C:\\Program Files\\Git\\bin\\bash.exe",
        "cursorColor": "#FFFFFF",
        "cursorShape": "bar",
        "fontFace": "Consolas",
        "fontSize": 10,
        "guid": "{72a69aca-322e-465d-a799-1d64dff65269}",
        "historySize": 9001,
        "icon": "C:\\Program Files\\Git\\git-bash.png",
        "name": "Git Bash",
        "padding": "0, 0, 0, 0",
        "snapOnInput": true,
        "startingDirectory": "%USERPROFILE%",
        "useAcrylic": false
      }

image

Just to add some notes I found (about the actual bash.exe path to use and startup parameters to launch a login shell):
https://stackoverflow.com/a/57369284/564226

You can find the Git for Windows icon at the following path:

C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zadjii-msft picture zadjii-msft  Â·  3Comments

ghost picture ghost  Â·  3Comments

mrmlnc picture mrmlnc  Â·  3Comments

alabuzhev picture alabuzhev  Â·  3Comments

mdtauk picture mdtauk  Â·  3Comments