From eb7ad6b21bee3832ca959466329e27569c599d84 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Mon, 10 Jun 2024 12:55:10 -0700 Subject: [PATCH] batman: Provide way to use BATMAN as MANPAGER --- doc/batman.md | 10 +++++++--- src/batman.sh | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/batman.md b/doc/batman.md index edc95fa..f3c5153 100644 --- a/doc/batman.md +++ b/doc/batman.md @@ -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 diff --git a/src/batman.sh b/src/batman.sh index b958152..e8af7a2 100755 --- a/src/batman.sh +++ b/src/batman.sh @@ -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