Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save swartzrock/d43bf815a62f2ce31aadefc45ca6ae6c to your computer and use it in GitHub Desktop.

Select an option

Save swartzrock/d43bf815a62f2ce31aadefc45ca6ae6c to your computer and use it in GitHub Desktop.

Grok tools faster with Batman, an llm-powered man page viewer with Markdown in bat.

This gist shows how to set up batman, a shell function, to render man pages in markdown with LLM-Now.

Installation

  1. Install LLM-Now using brew install swartzrock/tap/llm-now (macOS / Linux) or downloading a native executable from the releases page, plus bat and tldr.
  2. Set up an alias for a good provider and model in llm-now.
    1. I'm using haiku (Claude Haiku 4.5) here which works well.
    2. You can set up an alias by running llm-now and selecting Create a new shortcut….
  3. Download batman.sh and source it from your ~/.bashrc or ~/.zshrc shell configuration

Usage

batman tar (may take a few seconds depending on your local, cli, or cloud provider's LLM model).

Screenshots

image
#!/usr/bin/env bash
_batman_markdown() {
if command -v bat >/dev/null 2>&1; then
bat --language markdown
else
cat
fi
}
batman() {
if [ "$#" -eq 0 ]; then
printf 'usage: batman [section] page\n' >&2
return 2
fi
local command_name page lesson requested tldr_format tldr_output
requested="$*"
# The final argument is the page name in both `batman tar` and
# section-qualified calls such as `batman 5 passwd`.
for command_name do :; done
# Capture the man page without opening a pager; stop if `man` fails.
if ! page=$(MANPAGER=cat PAGER=cat man "$@"); then
return 1
fi
tldr_output=
tldr_format=
if command -v tldr >/dev/null 2>&1; then
if tldr_output=$(tldr --raw "$command_name" 2>/dev/null); then
tldr_format=markdown
elif tldr_output=$(NO_COLOR=1 tldr "$command_name" 2>/dev/null); then
tldr_format=text
else
tldr_output=
fi
fi
if ! lesson=$(
{
printf '%s\n\n' \
"Teach the '$requested' man page to a beginner.
Return Markdown only. Include:
- a concise mental model
- five useful flags or concepts
- two safe, practical examples
- one common mistake
Use only facts supported by the supplied man page.
If the page does not define five command-line flags, explain five useful concepts instead."
printf '%s\n' "$page" | col -b
} | llm-now haiku
); then
return 1
fi
{
if [ "$tldr_format" = markdown ] && [ -n "$tldr_output" ]; then
printf '## TL;DR\n\n%s\n\n---\n\n' "$tldr_output"
elif [ -n "$tldr_output" ]; then
printf '## TL;DR\n\n```text\n%s\n```\n\n---\n\n' "$tldr_output"
fi
printf '%s\n' "$lesson"
} | _batman_markdown
}
@swartzrock

Copy link
Copy Markdown
Author
image

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