Skip to content

Instantly share code, notes, and snippets.

@mdgrs-mei
Last active September 2, 2023 11:34
Show Gist options
  • Save mdgrs-mei/327d543bab91116471191c37d68268e2 to your computer and use it in GitHub Desktop.
Save mdgrs-mei/327d543bab91116471191c37d68268e2 to your computer and use it in GitHub Desktop.
Format file to add links to Select-String outputs
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<View>
<Name>MatchInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.MatchInfo</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>
<CustomEntry>
<CustomItem>
<ExpressionBinding>
<ScriptBlock>
$currentDir = (Get-Location).Path
$relativePath = $_.RelativePath($currentDir)
$originalLine = $_.ToEmphasizedString($currentDir)
if ($_.Path -and ($_.Path -ne 'InputStream'))
{
$linkString = $PSStyle.FormatHyperlink($relativePath, $_.Path)
$originalLine.Replace($relativePath, $linkString)
}
else
{
$originalLine
}
</ScriptBlock>
</ExpressionBinding>
</CustomItem>
</CustomEntry>
</CustomEntries>
</CustomControl>
</View>
</ViewDefinitions>
</Configuration>
@mdgrs-mei
Copy link
Author

mdgrs-mei commented Mar 21, 2023

You can apply the format with Update-FormatData command.

 Update-FormatData -PrependPath .\PathToTheDownloaded\Matchinfo.format.ps1xml

It works on Windows Terminal and PowerShell 7.2.

MatchinfoLinkFormat.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment