Skip to content

Instantly share code, notes, and snippets.

@vivainio
Last active February 3, 2025 07:57
Show Gist options
  • Save vivainio/9f9e0df550b3dfc2684a46cb0931876a to your computer and use it in GitHub Desktop.
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)
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