batman: Provide way to use BATMAN as MANPAGER

This commit is contained in:
Ethan P. 2024-06-10 12:55:10 -07:00
parent f5b8cfb5d7
commit eb7ad6b21b
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC
2 changed files with 17 additions and 3 deletions

View File

@ -13,13 +13,17 @@ If you have `fzf` installed, you can even use `batman` to search through manual
### As a Replacement for Man
Please do not use `batman` as the `MANPAGER`.
If you want to use `batman` instead of `man`, you should set a shell alias:
With bash:
```bash
alias man='batman' # bash
eval "$(batman --export-env)"
```
With fish:
```fish
batman --export-env | source
```
## Environment

View File

@ -22,10 +22,12 @@ hook_version
FORWARDED_ARGS=()
MAN_ARGS=()
BAT_ARGS=()
OPT_EXPORT_ENV=false
SHIFTOPT_SHORT_OPTIONS="SPLIT"
while shiftopt; do
case "$OPT" in
--export-env) OPT_EXPORT_ENV=true ;;
--paging|--pager) shiftval; FORWARDED_ARGS+=("${OPT}=${OPT_VAL}");
BAT_ARGS+=("${OPT}=${OPT_VAL}") ;;
*) MAN_ARGS+=("$OPT") ;;
@ -68,6 +70,14 @@ if [[ -n "${MANPAGER}" ]]; then BAT_PAGER="$MANPAGER"; fi
export MANPAGER="env BATMAN_IS_BEING_MANPAGER=yes bash $(printf "%q " "$SELF" "${FORWARDED_ARGS[@]}")"
export MANROFFOPT='-c'
# If `--export-env`, print exports to use batman as the manpager directly.
if "$OPT_EXPORT_ENV"; then
printf "export %s=%q\n" \
"MANPAGER" "$MANPAGER" \
"MANROFFOPT" "$MANROFFOPT"
exit 0
fi
# If no argument is provided and fzf is installed, use fzf to search for man pages.
if [[ "${#MAN_ARGS[@]}" -eq 0 ]] && [[ -z "$BATMAN_LEVEL" ]] && command -v "$EXECUTABLE_FZF" &>/dev/null; then
export BATMAN_LEVEL=1