Last active
April 20, 2021 07:00
-
-
Save dedale/85b603ea378caa34a397818b47ad46d9 to your computer and use it in GitHub Desktop.
Prefix cmd prompt with poetry project name
This file contains 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
:: 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 [92m$p$g[0m | |
:: 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 [97m$p# [37m | |
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 [95m%poetry_name% [92m$p [97m$$[0m | |
:skip_poetry | |
echo on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use raw code above for ESC character.