mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-12-12 17:20:40 +01:00
batman: Provide way to use BATMAN as MANPAGER
This commit is contained in:
parent
f5b8cfb5d7
commit
eb7ad6b21b
@ -13,13 +13,17 @@ If you have `fzf` installed, you can even use `batman` to search through manual
|
|||||||
|
|
||||||
### As a Replacement for Man
|
### As a Replacement for Man
|
||||||
|
|
||||||
Please do not use `batman` as the `MANPAGER`.
|
With bash:
|
||||||
If you want to use `batman` instead of `man`, you should set a shell alias:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
alias man='batman' # bash
|
eval "$(batman --export-env)"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With fish:
|
||||||
|
|
||||||
|
```fish
|
||||||
|
batman --export-env | source
|
||||||
|
```
|
||||||
|
|
||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
|
@ -22,10 +22,12 @@ hook_version
|
|||||||
FORWARDED_ARGS=()
|
FORWARDED_ARGS=()
|
||||||
MAN_ARGS=()
|
MAN_ARGS=()
|
||||||
BAT_ARGS=()
|
BAT_ARGS=()
|
||||||
|
OPT_EXPORT_ENV=false
|
||||||
|
|
||||||
SHIFTOPT_SHORT_OPTIONS="SPLIT"
|
SHIFTOPT_SHORT_OPTIONS="SPLIT"
|
||||||
while shiftopt; do
|
while shiftopt; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
|
--export-env) OPT_EXPORT_ENV=true ;;
|
||||||
--paging|--pager) shiftval; FORWARDED_ARGS+=("${OPT}=${OPT_VAL}");
|
--paging|--pager) shiftval; FORWARDED_ARGS+=("${OPT}=${OPT_VAL}");
|
||||||
BAT_ARGS+=("${OPT}=${OPT_VAL}") ;;
|
BAT_ARGS+=("${OPT}=${OPT_VAL}") ;;
|
||||||
*) MAN_ARGS+=("$OPT") ;;
|
*) 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 MANPAGER="env BATMAN_IS_BEING_MANPAGER=yes bash $(printf "%q " "$SELF" "${FORWARDED_ARGS[@]}")"
|
||||||
export MANROFFOPT='-c'
|
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 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
|
if [[ "${#MAN_ARGS[@]}" -eq 0 ]] && [[ -z "$BATMAN_LEVEL" ]] && command -v "$EXECUTABLE_FZF" &>/dev/null; then
|
||||||
export BATMAN_LEVEL=1
|
export BATMAN_LEVEL=1
|
||||||
|
Loading…
Reference in New Issue
Block a user