From 393cf1a37e7790645e7b752257a5418710930f14 Mon Sep 17 00:00:00 2001 From: Jacquin Moon Date: Sun, 8 Dec 2024 11:24:40 +0700 Subject: [PATCH] :sparkles: feat: powershell completion for `pyenv-win-venv` --- .../posh-completions/pyenv-win-venv.ps1 | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dotposh/Config/posh-completions/pyenv-win-venv.ps1 diff --git a/dotposh/Config/posh-completions/pyenv-win-venv.ps1 b/dotposh/Config/posh-completions/pyenv-win-venv.ps1 new file mode 100644 index 0000000..2a86592 --- /dev/null +++ b/dotposh/Config/posh-completions/pyenv-win-venv.ps1 @@ -0,0 +1,22 @@ +### pyenv-win-venv powershell completion + +$pyenvVenvCommand = (Get-Command 'pyenv-win-venv' -ErrorAction SilentlyContinue) + +if ($pyenvVenvCommand) { + if ($pyenvVenvCommand.ScriptContents | Select-String -Pattern 'completion') { + # Run pyenv-venv completion script asynchronously + Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -MaxTriggerCount 1 -Action { + &"pyenv-win-venv.ps1" completion | Out-String | Invoke-Expression + } | Out-Null + + } else { + # If there is no internet connection, then silently exit + if ((Test-Connection -ComputerName www.google.com -Count 1 -Quiet -ErrorAction Stop) -eq $False) { return } + + # Completion script from pyenv-win-venv fork repository: https://github.com/jacquindev/pyenv-win-venv + Invoke-RestMethod -Uri "https://raw.githubusercontent.com/jacquindev/pyenv-win-venv/refs/heads/main/completions/pyenv-win-venv.ps1" | + Invoke-Expression + } +} + +Remove-Variable pyenvVenvCommand