Skip to content

Instantly share code, notes, and snippets.

@YDX-2147483647
Last active December 24, 2023 09:24
Show Gist options
  • Save YDX-2147483647/7059a181236fab93b0d8430b98699868 to your computer and use it in GitHub Desktop.
Save YDX-2147483647/7059a181236fab93b0d8430b98699868 to your computer and use it in GitHub Desktop.
Help or see manual with bat.

Help or see manual with bat.

Add the following to your PowerShell $PROFILE, and try batman pip install.

<#
.SYNOPSIS
    Help or see manual with bat

.NOTES
    [bat](https://github.com/sharkdp/bat) should be installed and on your `$env:Path`.

.LINK
    https://gist.github.com/YDX-2147483647/7059a181236fab93b0d8430b98699868

.EXAMPLE
    batman Get-Command
.EXAMPLE
    batman pip
.EXAMPLE
    batman pip install
#>
function batman {
    $command = "$Args"; # as a string

    $is_pwsh_thing = $false;
    if ($Args.Length -eq 1) {
        switch (Get-Command $command) {
            { $_.CommandType -in @('Cmdlet', 'Function') } { $is_pwsh_thing = $true }
            { $_.CommandType -eq 'Alias' } {
                $is_pwsh_thing = (Get-Command ($_.ResolvedCommand)).CommandType -in @('Cmdlet', 'Function') ;
            }
            Default {}
        }
    }

    if ($is_pwsh_thing) {
        help $command -Full | bat -l man
    }
    else {
        Invoke-Expression "$command --help" | bat -l man
    }
}

To install bat, please check its documentation.

# On Windows
> scoop install less bat

For bash, batman.sh is better.

Features

  • Simple: no magic.
  • Compatible: Get-Help for PowerShell things, and --help for external scripts/binaries.
  • Better paging: move back, search, syntax highlighting. (compared to Out-Host -Paging and more.com)

Known issue

For aliases referenced to an application not on $env:Path and circular aliases, batman works as expected but throws redundant exceptions.

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