How To Get The Cwd In A Shell-dependend Format?
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 driv
Solution 1:
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
Post a Comment for "How To Get The Cwd In A Shell-dependend Format?"