bat: MANPAGER won't work on Mandoc's man implementation
What version of bat are you using?
0.15.4
Describe the bug you encountered:
Using export MANPAGER="sh -c 'col -bx | bat -l man -p'"
results in -bx: 1: Syntax error: Unterminated quoted string
Describe what you expected to happen? paging with bat
How did you install bat?
Void Linux package manager
** The bug ** It was already reported here for Termux, and it coudl well be the case for Alpine and other Mandoc’s man implementations cases. See https://github.com/termux/termux-packages/issues/4781#issuecomment-573110911
** Lazy solution **
Instead of recompiling man from GNU (https://www.nongnu.org/man-db/development.html)
one can be using export MANPAGER='nvim +Man!'
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 15 (1 by maintainers)
Commits related to this issue
- Add comment about Mandoc, closes #1145 — committed to sharkdp/bat by sharkdp 6 years ago
- Add batman.sh script for manpages with bat See https://github.com/sharkdp/bat/issues/1145 — committed to 8dcc/linux-dotfiles by 8dcc 4 years ago
Not that performance matters much for a shell script like this, but you can even cut out the cat invocation:
It does not work because mandoc does not do shell tokenization of the
$MANPAGERstring, it just splits it into a list of words and passes them toexecvp. So the error comes fromshwhich complains about an unterminated quoted string from the word'col.batitself does not have any problems displaying the output of mandoc’smancommand, you just have to configure the pager appropriately. This can be done by putting the following in a wrapper script and thenexport MANPAGER="your_wrapper":These two commands are not equivalent - the former reads from a file denoted by
$1and the latter reads from stdin. The former is required for mandoc, the latter may be required for other things that use$MANPAGER(e.g. using thehelpfunction in an ipython shell). The following can be used as a universal solution (note thatcathere is not as useless as in https://github.com/sharkdp/bat/issues/1145#issuecomment-736096036):You are all the way right 😉
Hey, so you have so much free time in your life huh?
It just bothered me when you don’t understand the code and saying it’s wrong. It’s not wrong. See, after you figure out what my code means, you already improve it. Good learning for you, right? 😉 I’ll take your offer then
Isn’t it obvious? But sure, have it your way… I don’t have much time and energy for something like this
For others: In ubuntu,
batis actuallybatcat, so setBAT_BINtobatorbatcatdepends on your environment.what else is the
else clausefor? The code means: if theinputis afilethen take the file, otherwise take thestdinDo I have to? One must be processed through
catand thencol, while the other just goes throughcolOr this for better performance: