Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created April 10, 2015 14:47
Show Gist options
  • Save dfinke/f045bdf71e646f635c9c to your computer and use it in GitHub Desktop.
Save dfinke/f045bdf71e646f635c9c to your computer and use it in GitHub Desktop.
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