Created
April 10, 2015 14:47
-
-
Save dfinke/f045bdf71e646f635c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Expand-Alias { | |
$Editor=$psISE.CurrentFile.Editor | |
$script=$Editor.Text | |
[ref]$errors=$null | |
[System.Management.Automation.PsParser]::Tokenize($script, $errors) | | |
Where { $_.Type -eq 'Command'} | | |
Sort StartLine, StartColumn -Desc | | |
ForEach { | |
if($_.Content -eq '?') | |
{ $result = Get-Command '`?' -CommandType Alias } | |
else | |
{ $result = Get-Command $_.Content -CommandType Alias -ErrorAction SilentlyContinue } | |
if($result) | |
{ | |
$Editor.Select($_.StartLine,$_.StartColumn,$_.EndLine,$_.EndColumn) | |
$Editor.InsertText($result.Definition) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment