by oising
24. August 2007 19:28
While I absolutely love MoW's PowerTab, there's been one little niggling thing that's been missing since day one; while you can navigate Types using the opening square bracket syntax, e.g. [<tab> , when using the new-object command this method is not totally syntactically compatible. (update: MoW explains in a comment below that there is a special trick for navigating without the square brackets, oops! me wrong!) You have to navigate to your type, then edit out the square brackets which is a little bit annoying. Also, when using this syntax you typically know exactly which type you need but can't remember the namespace. Or perhaps you know the type name, but don't want to have to type it all out (or navigate there).
So, I figured I'd crack open PowerTab and see how easy it was to implement. To cut a long story short, in about 30 minutes it was done. The thing that made it so easy was that MoW already has a DataSet in memory of all types and their namespaces, so the grunt work is done by a simple DataTable.Select call. I modified the function TabExpansion in TabExpansion.ps1 (version 0.96 b12), and put the following snippet just after the switch on $lastWord :
switch -regex ($lastWord) {
# Handle inline type search, e.g. new-object .identityreference<tab> or .identityre<tab>
'^\.(\w+)$' {
$typeName = $matches[1]
$types = $dsTabexpansion.tables["Types"]
$rowFilter = "name like '%.${typeName}%'"
$types.select($rowFilter) | % {$_["name"] } | Invoke-TabItemSelector $lastWord -Select $SelectionHandler
break;
}
The type search is initiated by prefixing the full or partial type name with a period (.) and then hitting tab. There you have it, inline type search. Have fun!
