Skip to content

Instantly share code, notes, and snippets.

@aldrichtr
Forked from mdgrs-mei/Matchinfo.Format.ps1xml
Created September 2, 2023 11:34
Show Gist options
  • Select an option

  • Save aldrichtr/9e5fa4585024d96dba7f92c68f793e79 to your computer and use it in GitHub Desktop.

Select an option

Save aldrichtr/9e5fa4585024d96dba7f92c68f793e79 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment