After installing the awesome posh-git stuff, I thought “it would be cool to have tab expansion for my psake tasks”. So, I read the posh-git stuff and decided it would be easy to follow the pattern they’ve used and adopt it for psake. That a complement on the job the posh-git guys have done and with only about 23 lines, a complement to the power of Powershell.
Anyway, below is how I integrated both posh-git and psake tab expansion into my powershell profile after including the PsakeTabExpansion.ps1 file.
# Set up tab expansion and include git expansion
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1]
switch -regex ($lastBlock) {
# Execute git tab completion for all git-related commands
'git (.*)' { GitTabExpansion $lastBlock }
'(Invoke-psake|psake) (.*)' { PsakeTabExpansion $lastBlock }
# Fall back on existing tab expansion
default { DefaultTabExpansion $line $lastWord }
}
}
The zip file has a readme w/ some sample code to drop in your profile. And the PsakeTabExpansion.ps1 flie, which I have in the same directory as my profile. I’m going to send the psake team, hopefully they will add it to the psake codebase.