Skip to content

Instantly share code, notes, and snippets.

@GhostofGoes
Last active October 18, 2018 03:20
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 GhostofGoes/03e40f5b642e0e1b35206027c9cd9c01 to your computer and use it in GitHub Desktop.
Save GhostofGoes/03e40f5b642e0e1b35206027c9cd9c01 to your computer and use it in GitHub Desktop.
PowerShell completion for Pipenv. Edit: "notepad $profile.CurrentUserAllHosts"
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
$aliases = @("pipenv") + @(Get-Alias | where { $_.Definition -eq "pipenv" } | select -Exp Name)
$aliasPattern = "($($aliases -join '|'))"
if($lastBlock -match "^$aliasPattern ") {
$Env:_PIPENV_COMPLETE = "complete-powershell"
$Env:COMMANDLINE = "$lastBlock"
(pipenv) | ? {$_.trim() -ne "" }
Remove-Item Env:_PIPENV_COMPLETE
Remove-Item Env:COMMANDLINE
}
elseif (Test-Path Function:\pipenvTabExpansionBackup) {
# Fall back on existing tab expansion
pipenvTabExpansionBackup $line $lastWord
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment