nodeenv icon indicating copy to clipboard operation
nodeenv copied to clipboard

Support for Git-bash on Windows.

Open jwmcgettigan opened this issue 5 years ago • 1 comments

This is the only method I could think of for detecting if a user is in a bash environment on a Windows machine - and thus the best solution I could think of to issue #226 .

I've made it so that if the user is on a Windows machine, it will check whether they are running nodeenv from a bash.exe terminal (such as git-bash). This is being done using psutil to check the name of all parent processes and run/install/treat as CYGWIN instead of as Windows if a bash.exe process is detected among these parent processes.

Please let me know what you think of this solution.

jwmcgettigan avatar Jun 26 '19 23:06 jwmcgettigan

I guess detecting if a sh.exe or bash.exe is on the PATH can be done using shutil.which and doing a is None check.

In [1]: import shutil

In [2]: shutil.which("sh.exe")
Out[2]: 'C:\\Program Files\\Git\\bin\\sh.exe'

In [3]: shutil.which("bash.exe")
Out[3]: 'C:\\Program Files\\Git\\bin\\bash.exe'

In [4]: shutil.which("not_on_path.exe")

In [5]: type(shutil.which("not_on_path.exe"))
Out[5]: NoneType

At least for me the platform.system() added in #263 does not work in git-bash 😥

In [6]: import platform

In [7]: platform.system()
Out[7]: 'Windows'

In [8]: is_CYGWIN = platform.system().startswith(('CYGWIN', 'MSYS'))

In [9]: is_CYGWIN
Out[9]: False

The added bonus of this method would be that even if you create the end in a different console (cmd or powershell) you would still get your activate file that you can source from git-bash (and ofc no extra dependency on psutil).

s-weigand avatar Jun 26 '22 22:06 s-weigand