2REM Windows Command Line Script (Batch) to deactivate virtual environment.
6REM * pyenv-virtualenv-init
8REM © 2025 Michael Paul Korthals. All rights reserved.
9REM For legal details see documentation.
13REM This script is located in the subfolder "shims"
14REM in the plugin root directory.
16REM Call it by name in the special Windows CMD terminal,
17REM which has been modified, calling "virtualenv.init".
19REM The script returns RC = 0 or another value in case of
22REM NOTE: Command "setlocal" would jeopardize the deactivation.
23REM All local variables are global inside the shell.
24REM Finally, these must be cleaned to reduce risks.
26if "%_PYENV_VENV_DEACTIVATE%"=="" goto error0
27if "%_PYENV_VENV_OLD_PROMPT%"=="" goto error0
28if "%_PYENV_VENV_OLD_PATH%"=="" goto error0
29REM Call "%_PYENV_VENV_DEACTIVATE%" and remember its return code
30call "%_PYENV_VENV_DEACTIVATE%" %*
31echo %ERRORLEVEL% > "%~dp0.deactivate_rc.~"
32REM DEBUG: echo Return code: %ERRORLEVEL%
33REM Restore the %_PYENV_VENV_OLD_PROMPT% before activating the virtual environment
34set "PROMPT=%_PYENV_VENV_OLD_PROMPT%"
35REM Restore the %_PYENV_VENV_OLD_PATH% from before activating the virtual environment
36set "PATH=%_PYENV_VENV_OLD_PATH%"
37REM Remove temporary variables
38set _PYENV_VENV_DEACTIVATE=
39set _PYENV_VENV_OLD_PROMPT=
40set _PYENV_VENV_OLD_PATH=
41REM Return deactivate return code
43set /p RC_STR=<"%~dp0.deactivate_rc.~"
45REM DEBUG: echo Return code: %RC%
46del "%~dp0.deactivate_rc.~"
47REM DEBUG: echo Return code: %RC%
50echo ␛[93mWARNING Virtual environment is not activated.␛[0m