sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.93k stars 1.26k forks source link

Losing bat when looking up man pages #3085

Open SamuelLarkin opened 2 months ago

SamuelLarkin commented 2 months ago

What steps will reproduce the bug? Following the suggested MANPAGER replacement here

sh -c 'col -bx | bat --language man --plain'

I get an error trying to read some man page

man quota

What happens?

sh: 1: bat: Permission denied
man: command exited with status 127: sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }' | LESS=-ix8RmPm Manual page quota(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page quota(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$--no-init --QUIET --RAW-CONTROL-CHARS --chop-long-lines --ignore-case --search-skip-screen --use-color --color=Sky MAN_PN=quota(1) sh -c col -bx | bat --language man --plain

Note that if you I do which bat after getting the error then try again man quota then I get the proper man pages through bat. It is as if bash forgot where to find bat but once I refresh its memory, it works.

What did you expect to happen instead?

To see the man pages for quota through the eye of bat.

How did you install bat?

cargo install --force bat


bat version and environment

Software version

bat 0.23.0

Operating system

Linux 5.15.0-119-generic

Command-line

bat --diagnostic

Environment variables

SHELL=/bin/bash
PAGER=<not set>
LESS='--no-init --QUIET --RAW-CONTROL-CHARS --chop-long-lines --ignore-case --search-skip-screen --use-color --color=Sky'
LANG=<not set>
LC_ALL=en_CA.UTF-8
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=<not set>
NO_COLOR=<not set>
MANPAGER='sh -c '\''col -bx | bat --language man --plain'\'''

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

Could not read contents of '$HOME/.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

Could not read contents of '$HOME/.cache/bat/metadata.yaml': No such file or directory (os error 2).

Custom assets

'$HOME/.cache/bat' not found

Compile time information

Less version

> less --version
less 590 (GNU regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
keith-hall commented 2 months ago

Are you able to use bat outside the context of a MANPAGER or do you get the same permission denied error initially? Maybe worth putting the full path to bat in your MANPAGER instead of just the executable name to see if it solves the issue

SamuelLarkin commented 2 months ago

It happened again. man nvidia-smi

sh: 1: bat: Permission denied
man: command exited with status 127: sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }' | LESS=-ix8RmPm Manual page nvidia-smi(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page nvidia-smi(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help or q to quit)$--no-init --QUIET --RAW-CONTROL-CHARS --chop-long-lines --ignore-case --search-skip-screen --use-color --color=Sky MAN_PN=nvidia-smi(1) sh -c col -bx | bat --language man --plain

I then immediately did bat <A_FILE> after getting the error and got the desired out aka the file's content. Then without doing which bat, I did man nvidia-smi worked as expected.

I'll try changing export MANPAGER="sh -c 'col -bx | bat --language man --plain'" to export MANPAGER="sh -c 'col -bx | ~/.local/bin/bat --language man --plain'" to see if I get the error.