Since I'm using both Windows' cmd.exe
and msysgit's bash
, trying to access the Windows-path output by os.getcwd()
is causing Python to attempt accessing a path starting with a drive letter and a colon, e.g. C:\
, which bash
correctly determines an invalid unix-path, which instead should start with /c/
in this example. But how can I modify a Windows-path to become its msys-equivalent iff the script is running within bash
?
Asked
Active
Viewed 174 times
0

Tobias Kienzler
- 25,759
- 22
- 127
- 221
-
related: [How to run a script which can determine whether cmd.exe or gnu mingw shell is running](https://stackoverflow.com/q/34651196/321973) – Tobias Kienzler May 18 '16 at 08:51
1 Answers
0
Ugly but should work unless you create an environment variable SHELL=bash
for Windows:
def msysfy(dirname):
import os
try:
shell = os.environ['SHELL']
except KeyError: # by default, cmd.exe has no SHELL variable
shell = 'win'
if os.path.basename(shell)=='bash' and dirname[1] == ':':
return '/' + dirname[0].lower() + '/' + dirname[2:]
# don't worry about the other backslashes, msys handles them
else:
return dirname

Tobias Kienzler
- 25,759
- 22
- 127
- 221