Skip to content

Instantly share code, notes, and snippets.

@nzbart
Created May 14, 2015 00:19
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 nzbart/27248a01b43cb0000994 to your computer and use it in GitHub Desktop.
Save nzbart/27248a01b43cb0000994 to your computer and use it in GitHub Desktop.
Chain a PowerShell script block to the tabexpansion2 function, calling the original implementation if the new one doesn't return a result.
function Add-TabExpansion
{
param([ScriptBlock][parameter(mandatory)]$ScriptBlock)
$originalFunction = (gcm TabExpansion2).ScriptBlock
$chainedBlock = {
$userResult = & $ScriptBlock @Args
if($userResult) {
return $userResult
}
return & $originalFunction @Args
}.GetNewClosure()
Set-Content Function:\TabExpansion2 $chainedBlock
}
Add-TabExpansion @Args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment