Skip to content

Instantly share code, notes, and snippets.

@Pendrokar
Last active January 25, 2017 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pendrokar/a7fc59791d4eb113ea0f4670274f18b6 to your computer and use it in GitHub Desktop.
Save Pendrokar/a7fc59791d4eb113ea0f4670274f18b6 to your computer and use it in GitHub Desktop.
Access Git in command prompt from within 'Bash on Ubuntu on Windows' environment by having this within environment variables. I am not a good Batch script writer though.
@echo off
SETLOCAL EnableDelayedExpansion
rem Get drive letter along with the colon and backslash
SET _cdDrive=%cd:~0,3%
rem Get drive letter
SET mntPath=%_cdDrive:~0,1%
rem mnt/<driveLetter> is lower case, has to be converted
call :LoCase mntPath
SET mntPath=/mnt/%mntPath%/
rem Get all received arguments
SET fullWinArguments=%*
rem Replace <WindowsDrive>:\
SET fullLinuxArguments=!fullWinArguments:%_cdDrive%=%mntPath%!
rem Replace backslahes with Linux forward-slashes
SET fullLinuxArguments=!fullLinuxArguments:\=/!
bash -c 'git %fullLinuxArguments%'
GOTO:EOF
:LoCase
:: Subroutine to convert a variable VALUE to all lower case.
:: The argument for this subroutine is the variable NAME.
SET %~1=!%1:A=a!
SET %~1=!%1:B=b!
SET %~1=!%1:C=c!
SET %~1=!%1:D=d!
SET %~1=!%1:E=e!
SET %~1=!%1:F=f!
SET %~1=!%1:G=g!
SET %~1=!%1:H=h!
SET %~1=!%1:I=i!
SET %~1=!%1:J=j!
SET %~1=!%1:K=k!
SET %~1=!%1:L=l!
SET %~1=!%1:M=m!
SET %~1=!%1:N=n!
SET %~1=!%1:O=o!
SET %~1=!%1:P=p!
SET %~1=!%1:Q=q!
SET %~1=!%1:R=r!
SET %~1=!%1:S=s!
SET %~1=!%1:T=t!
SET %~1=!%1:U=u!
SET %~1=!%1:V=v!
SET %~1=!%1:W=w!
SET %~1=!%1:X=x!
SET %~1=!%1:Y=y!
SET %~1=!%1:Z=z!
GOTO:EOF
@Pendrokar
Copy link
Author

Command prompt even displays color coding.
Command prompt even displays color coding

@Pendrokar
Copy link
Author

Updated Batch file so that it converts drive letter to /mnt/[DriveLetter]. Example:
C:\Users\Yanis Lukes\Documents\My Games\GalCiv3\Mods\StarControl>git status "C:\Users\Yanis Lukes\Documents\My Games\GalCiv3\Mods\StarControl\Game"
=>git status "/mnt/c/Users/Yanis Lukes/Documents/My Games/GalCiv3/Mods/StarControl/Game"

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