Skip to content

Instantly share code, notes, and snippets.

@juntalis
Created September 6, 2014 16:09
Show Gist options
  • Save juntalis/8d5a1fab60d86321413f to your computer and use it in GitHub Desktop.
Save juntalis/8d5a1fab60d86321413f to your computer and use it in GitHub Desktop.
@echo off
goto main
:dirname
call set %~1=%~dp2
call set %~1=%%%~1:~0,-1%%
goto :EOF
:get_virtualenv
rem If the foldername of the virtual env contains a dot, (ex: .vip)
rem part of the foldername will end up in the extension part of the path.
rem Because of that, we'll combine the extension and name parts of the
rem path.
set PROMPT=(%~nx1) %PROMPT%
goto :EOF
:main
rem Set virtualenv Root
call :dirname VIRTUAL_ENV "%~f0"
call :dirname VIRTUAL_ENV "%VIRTUAL_ENV%"
rem Set up our prompt.
if not defined PROMPT set PROMPT=$P$G
if not defined _OLD_VIRTUAL_PROMPT set _OLD_VIRTUAL_PROMPT=%PROMPT%
call :get_virtualenv "%VIRTUAL_ENV%"
rem Setup python home and back up if necessary
if defined PYTHONHOME (
if not defined _OLD_VIRTUAL_PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=
)
rem Check if we need to reset
if defined _OLD_VIRTUAL_PATH (
set PATH=%_OLD_VIRTUAL_PATH%
goto skip_path
)
set _OLD_VIRTUAL_PATH=%PATH%
:skip_path
setlocal
call :dirname BINDIR "%~f0"
set PATH=%BINDIR%;%PATH%
rem Not really necessary, but clean up any blank entries.
endlocal & set PATH=%PATH:;;=;%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment