Karl Prosser turned on a new Open Source CodePlex project, PowerShell ISE-Cream.
Community extensions for Powershell ISE(Integrated Scripting Environment), to allow custom hotkeys for code execution, editing, exporting, as well as color themes and such
On the lists of blogged extensions he included my Expand-Alias for PowerShell Integrated Scripting Environment and commented we might want to add just the one the cursor is near.
Great Idea Karl
I re-factored the code, below are the two extensions, Expand-Alias and Expand-CurrentAlias
Function Expand-Alias {
$content=$psise.CurrentOpenedFile.Editor.text
[System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |
Where { $_.Type -eq 'Command'} |
Sort StartLine, StartColumn -Desc | Do-Expansion
}
Function Expand-CurrentAlias {
$CaretColumn = $psise.CurrentOpenedFile.Editor.CaretColumn
$content=$psise.CurrentOpenedFile.Editor.text
[System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |
Where { $_.Type -eq 'Command'} |
Where { $CaretColumn -eq $_.StartColumn -Or
$CaretColumn -eq $_.EndColumn} | Do-Expansion
}
Filter Do-Expansion {
if($_.Content -eq '?') {
$result = Get-Command '`?' -CommandType Alias
} else {
$result = Get-Command $_.Content -CommandType Alias -ErrorAction SilentlyContinue
}
if($result) {
$psise.CurrentOpenedFile.Editor.Select($_.StartLine,$_.StartColumn,$_.EndLine,$_.EndColumn)
$psise.CurrentOpenedFile.Editor.InsertText($result.Definition)
}
}
$null = $psISE.CustomMenu.Submenus.Add("Expand Alias", {Expand-Alias}, 'Ctrl+Shift+E')
$null = $psISE.CustomMenu.Submenus.Add("Expand Current Alias", {Expand-CurrentAlias}, 'Ctrl+Shift+W')
Thanks for kicking off the project Karl.
{ 1 trackback }
{ 0 comments… add one now }