Last active
February 3, 2025 07:57
-
-
Save vivainio/9f9e0df550b3dfc2684a46cb0931876a to your computer and use it in GitHub Desktop.
Powershell function to run tasks.py in current or any parent dirertory. Add this to your powershell profile ($PROFILE)
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
function pt { | |
$currentDir = Get-Location | |
$parentDir = $currentDir | |
while ($parentDir -ne [System.IO.Path]::GetPathRoot($parentDir)) { | |
$tasksPyPath = Join-Path -Path $parentDir -ChildPath "tasks.py" | |
$venvPath = Join-Path -Path $parentDir -ChildPath ".venv" | |
if (Test-Path $tasksPyPath) { | |
Set-Location $parentDir | |
if (Test-Path $venvPath) { | |
uv run tasks.py $args | |
} else { | |
python tasks.py $args | |
} | |
Set-Location $currentDir | |
return | |
} | |
$parentDir = Get-Item $parentDir | Select-Object -ExpandProperty Parent | |
} | |
Write-Host "tasks.py not found in any parent directory." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment