Skip to content

Instantly share code, notes, and snippets.

@duebbert
Created July 12, 2017 08:27
Show Gist options
  • Save duebbert/c4f26c9d0691b7d4a0e932e7d9f36271 to your computer and use it in GitHub Desktop.
Save duebbert/c4f26c9d0691b7d4a0e932e7d9f36271 to your computer and use it in GitHub Desktop.
git batch file for using with Bash on Ubuntu on Windows
@echo off
SETLOCAL enableextensions enabledelayedexpansion
:: Thanks:
:: - https://stackoverflow.com/questions/37000166/getting-pycharm-to-recognize-python-on-the-windows-linux-subsystem-bash-on-wind
:: ###################################################################################
:: Set up the current directory, so that we can change into it before calling git
:: ###################################################################################
:: Extract the drive letter
SET "DIR=%cd%"
:: Convert drive letter to lower case and add /mnt/
FOR %%i IN ("A:\=/mnt/a/" "B:\=/mnt/b/" "C:\=/mnt/c/" "D:\=/mnt/d/" "E:\=/mnt/e/" "F:\=/mnt/f/" "G:\=/mnt/g/" "H:\=/mnt/h/" "I:\=/mnt/i/" "J:\=/mnt/j/" "K:\=/mnt/k/" "L:\=/mnt/l/" "M:\=/mnt/m/" "N:\=/mnt/n/" "O:\=/mnt/o/" "P:\=/mnt/p/" "Q:\=/mnt/q/" "R:\=/mnt/r/" "S:\=/mnt/s/" "T:\=/mnt/t/" "U:\=/mnt/u/" "V:\=/mnt/v/" "W:\=/mnt/w/" "X:\=/mnt/x/" "Y:\=/mnt/y/" "Z:\=/mnt/z/") DO CALL SET "DIR=%%DIR:%%~i%%"
:: Change backslash to forward slash. Must run after converting the drive letter.
SET "DIR=%DIR:\=/%"
:: ###################################################################################
:: Fix the arguments
:: ###################################################################################
SET ARGS=%*
:: Convert drive letter to lower case and add /mnt/
FOR %%i IN ("A:\=/mnt/a/" "B:\=/mnt/b/" "C:\=/mnt/c/" "D:\=/mnt/d/" "E:\=/mnt/e/" "F:\=/mnt/f/" "G:\=/mnt/g/" "H:\=/mnt/h/" "I:\=/mnt/i/" "J:\=/mnt/j/" "K:\=/mnt/k/" "L:\=/mnt/l/" "M:\=/mnt/m/" "N:\=/mnt/n/" "O:\=/mnt/o/" "P:\=/mnt/p/" "Q:\=/mnt/q/" "R:\=/mnt/r/" "S:\=/mnt/s/" "T:\=/mnt/t/" "U:\=/mnt/u/" "V:\=/mnt/v/" "W:\=/mnt/w/" "X:\=/mnt/x/" "Y:\=/mnt/y/" "Z:\=/mnt/z/") DO CALL SET "ARGS=%%ARGS:%%~i%%"
:: Backslash to forward slash
SET ARGS=!ARGS:\=/!
:: ###################################################################################
:: Execute it!!!
:: ###################################################################################
If %PROCESSOR_ARCHITECTURE% == x86 (
C:\Windows\sysnative\bash.exe --login -c '. ~/start_keepass_agent.sh; cd "%DIR%"; git %ARGS%'
) Else (
bash.exe --login -c '. ~/start_keepass_agent.sh; cd "%DIR%"; git %ARGS%'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment