Created
December 16, 2016 12:05
-
-
Save spiritualized/37db4e18b964ec54631ba79590391ac3 to your computer and use it in GitHub Desktop.
Python virtualenv activate.bat (Windows) - derive prompt title from virtualenv directory's parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set "VIRTUAL_ENV=C:\path\to\project\venv" | |
CALL :RESOLVE "%VIRTUAL_ENV%\.." PromptName | |
for %%f in (%PromptName%) do set PromptName=%%~nxf | |
if defined _OLD_VIRTUAL_PROMPT ( | |
set "PROMPT=%_OLD_VIRTUAL_PROMPT%" | |
) else ( | |
if not defined PROMPT ( | |
set "PROMPT=$P$G" | |
) | |
set "_OLD_VIRTUAL_PROMPT=%PROMPT%" | |
) | |
set "PROMPT=(%PromptName%) %PROMPT%" | |
REM Don't use () to avoid problems with them in %PATH% | |
if defined _OLD_VIRTUAL_PYTHONHOME goto ENDIFVHOME | |
set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%" | |
:ENDIFVHOME | |
set PYTHONHOME= | |
REM if defined _OLD_VIRTUAL_PATH ( | |
if not defined _OLD_VIRTUAL_PATH goto ENDIFVPATH1 | |
set "PATH=%_OLD_VIRTUAL_PATH%" | |
:ENDIFVPATH1 | |
REM ) else ( | |
if defined _OLD_VIRTUAL_PATH goto ENDIFVPATH2 | |
set "_OLD_VIRTUAL_PATH=%PATH%" | |
:ENDIFVPATH2 | |
set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%" | |
GOTO :EOF | |
:RESOLVE | |
SET %2=%~f1 | |
GOTO :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment