Skip to content

Add support for WSL Bash on Windows 10 #4641

Closed

Description

@shiftkey

Is your feature request related to a problem? Please describe.
Windows Subsystem for Linux has available bash environment that's available as an optional extra in recent versions of Windows 10.

screen shot 2018-05-09 at 2 08 05 pm

It would be nice to light this up as an option in Desktop and let users choose this shell.

Describe the solution you'd like
The checks that Desktop need to perform should be added into app/src/lib/shells/win32.ts and we have documentation outlining how to add support for additional shells.

The high-level steps for looking this up are basically:

  • are you on Windows 10? If not, return false
  • Have you enabled WSL? This seems to be the magic registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Notifications\OptionalFeatures\Microsoft-Windows-Subsystem-Linux and it contains these values:

If not found inthe registry, return false

  • Lastly, does C:\Windows\System32\bash.exe exist on disk. That seems to be enough for an entry point but it'd also be nice to be able to detect that you have a Linux distro installed (otherwise you would see a prompt to visit the store and install, which is fine).

We need to ensure that it launches in the user's repository, and I think we can lean on cwd like this:

return spawn(pathToBashExe, [ ], {
  shell: true,
  cwd: path,
})

EDIT: @JordanMussi added some extra context from their setup below - feel free to use that alongside the above rules.

Teachability, Documentation, Adoption, Migration Strategy

This should all just work, but I'm not sure on the right label for this shell to prevent it from being confused with Git Bash. In the start menu you search on the Linux distro you have, which means support for multiple distros is possible - maybe that's a stretch goal for this?

Activity

  1. added
    help wanted
    windows
    on May 9, 2018
  2. JordanMussi commented on May 9, 2018

    @JordanMussi
    Contributor

    Lastly, does C:\Windows\System32\bash.exe exist on disk. That seems to be enough for an entry point but it'd also be nice to be able to detect that you have a Linux distro installed (otherwise you would see a prompt to visit the store and install, which is fine).

    There is also C:\Windows\System32\wsl.exe which is my preferred entry over bash since it respects using a shell other than /bin/bash (see more below). I prefer executing the command within Hyper rather than using the terminal window the exes launch themselves. Supporting this would add unnecessary complexity and it isn't much effort to choose the desired terminal as the shell to launch in GitHub and then launch the shell manually from there.

    In the start menu you search on the Linux distro you have, which means support for multiple distros is possible - maybe that's a stretch goal for this?

    It looks like using the name of the distro as a command launches the correct shell.

    wslconfig /list can be used to find which distros are installed (once the app knows WSL is installed).

    4641-wslconfig

    As you can see above, I only have Ubuntu installed, I've just tested using ubuntu and it is slightly different to wsl and bash. Note that the increased time for wsl/ubuntu is due to launching ZSH.

    • bash and wsl launch with a pwd of the path launched from but ubuntu does not (I tried this advice using the start command but ubuntu still launches to ~). This limitation is actually mentioned on the linked documentation page:

      The disadvantage of running a distribution from the command line in this way is that it will automatically change your working directory from the current directory to the distribution's home directory.

    • wsl and ubuntu respect the default shell chosen with chsh but bash launches /bin/bash

    4641-shells

    Running where ubuntu.exe in cmd.exe gives me the path C:\Users\Jordan\AppData\Local\Microsoft\WindowsApps\ubuntu.exe so I presume the other distributions' launchers will land there too. However I'm not sure how reliably the executable name can be determined from the wslconfig /list command since there doesn't seem to be a strict naming scheme. Sure you can assume it's the name given but lower case, except this might not be true for future distributions.

  3. shiftkey commented on May 9, 2018

    @shiftkey
    MemberAuthor

    @JordanMussi thanks for that extra context!

  4. minonl commented on Jun 21, 2018

    @minonl

    @shiftkey Does this issue and #4657 actually enable us to start github client from WSL directly?
    Currently when execue in WSL(and WSL inside Hyper) fails:

    min@MMM:/mnt/d/joe5y$ github
    sh: 0: Can't open /mnt/d/joe5y/AppData/Local/GitHubDesktop/bin/..\app-1.2.3\resources\app\static\github.sh
    min@MMM:/mnt/d/joe5y$
    
  5. shiftkey commented on Jun 21, 2018

    @shiftkey
    MemberAuthor

    @minvedacat that's a separate issue to this (please open an issue so we're tracking it).

    This is the script, but I didn't test it from WSL at the time I was working on it. It works from Git Bash, so I'd love to get to the bottom of what's different between the two as that error doesn't make sense to me at first glance.

  6. added
    integrations
    and removed on Jul 3, 2018
  7. jayschwa commented on Jan 8, 2019

    @jayschwa
    Contributor

    #6420 is waiting for review. cc @shiftkey

  8. ADustyOldMuffin commented on Jun 14, 2019

    @ADustyOldMuffin
    Contributor

    @shiftkey I'd be interested in taking this over since it seems to be almost done and in need of a owner.

  9. tierninho commented on Jun 14, 2019

    @tierninho
    Contributor

    @ADustyOldMuffin Go for it! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedintegrationswindows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions