Skip to content

Commit

Permalink
Add bat highlighting for PowerShell help
Browse files Browse the repository at this point in the history
  • Loading branch information
kelleyma49 committed Oct 19, 2024
1 parent 5ef833d commit 0a42ef2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion helpers/PsFzfTabExpansion-Parameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ $command = $args[0]
$parameter = $args[1]
$parameter = $parameter.replace('-', '')

$RunningInWindowsTerminal = [bool]($env:WT_Session)
$IsWindowsCheck = ($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows
$ansiCompatible = $script:RunningInWindowsTerminal -or (-not $script:IsWindowsCheck)

if ([System.Management.Automation.Cmdlet]::CommonParameters.Contains($parameter)) {
$tempFile = New-TemporaryFile
Get-Help about_CommonParameters | out-file $tempFile
Expand All @@ -13,5 +17,10 @@ if ([System.Management.Automation.Cmdlet]::CommonParameters.Contains($parameter)
Remove-Item $tempFile -ErrorAction SilentlyContinue
}
else {
Get-Help -Name $Command -Parameter $parameter
if ($ansiCompatible -and $(Get-Command bat -ErrorAction Ignore)) {
Get-Help -Name $Command -Parameter $parameter | bat --language=markdown --color always --style=plain
}
else {
Get-Help -Name $Command -Parameter $parameter
}
}
9 changes: 7 additions & 2 deletions helpers/PsFzfTabExpansion-Preview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ else {
}
# is directory?
if (Test-Path $path -PathType Container) {

Get-ChildItem $path

if (Get-Command git -ErrorAction Ignore) {
Expand Down Expand Up @@ -46,7 +45,13 @@ elseif (Test-Path $path -PathType leaf) {
elseif (($cmdResults = Get-Command $Item -ErrorAction Ignore)) {
if ($cmdResults) {
if ($cmdResults.CommandType -ne 'Application') {
Get-Help $Item
if ($ansiCompatible -and $(Get-Command bat -ErrorAction Ignore)) {
Get-Help $Item | bat --language=markdown --color always --style=plain
}
else {

}

}
else {
# just output application location:
Expand Down

0 comments on commit 0a42ef2

Please sign in to comment.