# Handle "about_*" help manuals
'\s*(about_[\w|\d]*)' {
$matched = $matches[1]
$helpFileNames = Get-Help $matched | Sort-Object Name | Select-Object Name
if ($helpFileNames.Length -ne $null) {
$helpFileNames | foreach {
# extract manual name(NOTE:same RegEx pattern)
$m = [RegEx]::Matches($_.Name, '\s*(about_[\w|\d]*)')
$m[0].Value
}
}
}
In this version, i have added functionality to expand "about_[tab]" manual files.
Now you can do;
- about_[Tab] -> about_Alias
- about_r[Tab] -> about_regular_expression
- about_regular_[Tab] -> about_regular_expression
- about_u[Tab] -> about_ubiquitous_parameters
When you do get-help about_alias, See Also section mentions about_variable manual.
If you try "about_v[Tab]" it would not work because there is no manual file named about_variable.help.txt in $pshome.
Now it should be apparent now how I have implemented my functionality.
It basically checks for manual file name that matches "about_blah*" against manual file names on $PSHOME directory.
switch -regex ($lastWord)Add above piece of code to "TabExpansion.ps1", go to wherever you have saved the file and ". .\TabExpansion.ps1" and you are good to go.
{
#
# Other functionalities...
#
# Handle "about_*" help manuals
'\s*(about_[\w\d]*)' {
$matched = $matches[1]
# Search for manual file name in $PSHOME
$helpFileNames = Get-ChildItem "$pshome/$($matched)*.help.txt" | Sort-Object Name | Select-Object Name
if ($helpFileNames -ne $null) {
$helpFileNames foreach {
# extract manual name(NOTE:same RegEx pattern)
$m = [RegEx]::Matches($_.Name, '\s*(about_[\w\d]*)')
$m[0].Value
}
}
}
# ...
For previous blog posts(mine or /\/\o\/\/'s)on "TabExpansion", go check out "http://del.icio.us/powershell/TabExpansion"
Tags : Monad msh PowerShell
Using het_help may speed it up :
ReplyDeletePoSH>(measure-command {Get-ChildItem "$pshome/about_*.help.txt"}).TotalMilliseconds
46.8331
PoSH>(measure-command {get-help about_*}).TotalMilliseconds
16.745
Greetings /\/\o\/\/
Works great. I missed that, too :-)
ReplyDeleteThanks for the feedback guys~
ReplyDeleteMow, I have editted the previous code as you have suggested ;) thanks~
Would you mind posting your COMPLETE TabExpansion somewhere again? The Pastebin.com stuff is gone.
ReplyDeleteI have reposted here.
ReplyDeletehttp://pastehere.com/?armhfr
Uhm, I am still trying to add more stuff on the function, so i have broken one of mow's tab functionality($host.ui.rawUi.[tab] wouldn't work)
I will try to update the working version up on the blog page...
But this one has only one more functionality which is to expand an alias into its original cmdlet/function name.
So "ls[tab]" would result in "Get-ChildItem" and "sal[tab]" to "Set-Alias" etc...
Could you start reving the version number when you make changes. So far I've ended up looking through the source on my system to figure out if I have the latest version.
ReplyDeleteHello there, Steve?
ReplyDeleteAh, i haven't actually added the source for TabExpansion function to a source control at the time working on this function.
But i have added tab function into a source control, so when I update the source next time, it will start from version 1.