Skip to content

Instantly share code, notes, and snippets.

@dedale
Last active April 20, 2021 07:00
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 dedale/85b603ea378caa34a397818b47ad46d9 to your computer and use it in GitHub Desktop.
Save dedale/85b603ea378caa34a397818b47ad46d9 to your computer and use it in GitHub Desktop.
Prefix cmd prompt with poetry project name
:: Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun="%USERPROFILE%\AutoRun.cmd"
:: (replace USERPROFILE with actual value)
@echo off
:: skip if already done
if "%RC_CMD%"=="1" goto :skip
cls
prompt $p$g
:: Update PATH
::set PATH=...;%PATH%
:: Misc extra stuff
::set _NT_SYMBOL_PATH=srv*C:\symbols*http://msdl.microsoft.com/downloads/symbols
:: Custom stuff if admin
net session 1>nul 2>nul && (
prompt $p# 
color 47
cd /D %HOMEPATH%
)
set RC_CMD=1
:skip
if not "%POETRY_ACTIVE%"=="1" goto :skip_poetry
setlocal
set poetry_root=
call :find_poetry_root %cd%
goto :found_poetry_root
:find_poetry_root
if exist "%~f1\pyproject.toml" (
set poetry_root=%~f1
goto :eof
)
if "%~p1"=="\" goto :eof
call :find_poetry_root %~f1\..
goto :eof
:found_poetry_root
if "%poetry_root%"=="" goto :skip_poetry
findstr /C:"name\ =" "%poetry_root%\pyproject.toml">"%poetry_root%\.name"
set /p poetry_name=<"%poetry_root%\.name"
del "%poetry_root%\.name"
set poetry_name=%poetry_name:~8,-1%
endlocal && prompt %poetry_name% $p $$
:skip_poetry
echo on
@dedale
Copy link
Author

dedale commented Mar 28, 2021

image

Use raw code above for ESC character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment