Skip to content

Instantly share code, notes, and snippets.

@originalmind
Last active December 29, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save originalmind/7635990 to your computer and use it in GitHub Desktop.
Save originalmind/7635990 to your computer and use it in GitHub Desktop.
Add the PortableGit (supplied by GitHub for Windows) bin directory to your PATH variable and then start your console
@rem Usage: set-gitbin-start-console.bat "C:\path\to\my\console.exe"
@echo off
if "%1" == "" GOTO ErrorPathNotSpecified
@rem limit the scope of the changes to environment variables
setlocal
@rem todo: set GITHUB_ROOT from registry
SET GITHUB_ROOT=%USERPROFILE%\AppData\Local\GitHub\
@rem Get the most recently created version of PortableGit
FOR /f "delims=" %%F IN ('dir %GITHUB_ROOT%\PortableGit* /O:-D /T:C /B') DO (
set filename=%%F
goto SetPath
)
:SetPath
SET GIT_ROOT=%GITHUB_ROOT%%filename%
@echo Adding Portable Git location to path: %GIT_ROOT%
@if not exist %GIT_ROOT% GOTO ErrorNotFound
@set PATH=%GIT_ROOT%\bin;%GIT_ROOT%\cmd;%PATH%
GOTO StartShell
:ErrorNotFound
@echo Sorry can't find git path.
@rem We'll start the shell anyway so the user will see this error
:StartShell
@cmd /k %1
:ErrorPathNotSpecified
@echo Please specify the path to your shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment