/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" PowerShell out-DataGrid update and more Dataset ut... "," PowerShell : Getting Subdirectories using WMI part... "," PowerShell : Getting Subdirectories using WMI part... "," PowerShell : Getting Subdirectories using WMI "," PowerShell basic parameter checking of a function "," PowerShell Celsius Fahrenheit converting "," PowerShell : How Can I Rename Files Using File Nam... "," PowerShell make a drive of an UNC path "," Some Powershell News "," PowerShell Import and Export a DirectoryTree and S... "," ")

Sunday, May 28, 2006


PowerShell Tab Completion

PowerShell Tab Completion is since RC1 customizable,

you can look at the current implementation like this :

get-content function:TabExpansion

This is my first customization to this function :

I added Tab-completion for Types to get the static methods (and properties)
I like this especialy becouse normaly you have to remember to use get-member - static to list them.

This also works for Enums :

[regex]::M [tab]

[dateTime]:: [tab]

[consolecolor]::B [tab]
[consolecolor]::Black [tab]
[consolecolor]::Blue [tab]

the Code I added looks like this :

function tabexpansion {

# (Original Code Here )

            switch -regex ($lastWord)

# this Part is added to handle Types
# /\/\o\/\/ 2006
               # Handle Types
               '(\[.*\])::(\w*)' {
                    invoke-expression "$($matches[1]) | gm -static" | where {$_.name -like "$($matches[2])*"} |% {
                      if ($_.MemberType -band $method) {
                        "$($matches[1])::$($_.name)" + '('
                      } Else {

# End of added Part

               # Handle property and method expansion...

# (Original Code Here )


*Note* if you output the original code to a file (gc function:TabExpansion | out-file) you will miss the line "Function {" and the last "}" you need to add it to declare the function again.

then below the Switch statement (I left in in for readability, you add the custom code.

you need to . source the script to overwrite the $global tabExpansion function.
and put it in your profile to use it every session.


gr /\/\o\/\/
Tags :

Anonymous Jacques
This is a great addition to the tab completion function! Leveraging on your work, I have added completion functionality for type names themselves:

# janel 2006
# Handle Type Names
'\[(.*)' {
[appdomain]::CurrentDomain.getassemblies() | % {$_.GetTypes() | ? {($_.FullName -like "$($matches[1])*") -or ($_.FullName -like "System.$($matches[1])*")} | % {"[$($_.FullName)]"}}

[system.date [tab]

It also resolves a type name if you omit 'system':
[date [tab]
Blogger /\/\o\/\/

thanks a lot for those additions !,
they where on my wishlist also.

only on my work PC this was to slow.

so I think I it would be good to only get the
[appdomain]::CurrentDomain.getassemblies() once and put it in to a $global variable and check from the function if its filled yet.
to speed it up

thanks again

Greetings /\/\o\/\/
Blogger /\/\o\/\/
about the break,
I have got it I forgot to past it into my blog
Blogger /\/\o\/\/
I changed your addition to fill a datatable with the assamlynames the first time and from then on use the datatable, this speeds it up a lot, only I miss the sublevels for now. to go level by level.
# janel 2006
# /\/\o\/\/ 2006 changed to cache assemblies
# todo go level by level
# Handle Type Names
'\[(.*)' {
if (!($global:dtAssemblies)) {
$global:dtAssemblies = new data.datatable
[appdomain]::CurrentDomain.getassemblies() | % {$_.GetTypes()} |% {$global:dtAssemblies.rows.add("$_.fullname")}
switch ($matches[1].length - $matches[1].replace('.','').length) {
0 {"[system"}
1 { $global:dtAssemblies.select("name like '$($matches[1])%'") |% {"[$($_.name)"}}
default { $global:dtAssemblies.select("name like '$($matches[1])%'") |% {"[$($_.name)"}}
Post a Comment

Links to this post:

Create a Link

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?