sharkdp / bat

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

Syntax highlighting doesn't work properly for fish man pages #3025

Open injust opened 2 weeks ago

injust commented 2 weeks ago

What steps will reproduce the bug?

  1. Use fish shell
  2. set -Ux MANPAGER "sh -c 'col -bx | bat -l man -p'"
  3. type --help, fish_add_path --help, etc.

What happens? Anything that isn't indented is syntax highlighted orange, ignoring any actual formatting.

What did you expect to happen instead? The man page should be highlighted reasonably.

I think this might be happening because fish's man pages aren't indented? But I couldn't find anything suggesting that man page sections have to be indented, so if this is the reason, then the syntax highlighting should be able to tolerate fish's non-indented man page format.

How did you install bat?

Homebrew


Software version

bat 0.24.0

Operating system

macOS 14.5 (Darwin 23.5.0)

Command-line

bat --diagnostic 

Environment variables

SHELL=/usr/local/bin/fish
PAGER=<not set>
LESS=<not set>
LANG=en_CA.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<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=truecolor
NO_COLOR=<not set>
MANPAGER='sh -c '\''col -bx | bat --language=man --style=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 '/Users/jsu/.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

bat_version: 0.24.0
creation_time:
  secs_since_epoch: 1719638264
  nanos_since_epoch: 856140000

Custom assets

Compile time information

Less version

> less --version 
less 643 (PCRE2 regular expressions)
Copyright (C) 1984-2023  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
flohw commented 1 week ago

Hi,

I have a similar issue, I think. I use zsh 5.9, bat 0.24 (installed via arch official repository) and I have MANPAGER=sh -c 'col -bx | bat -l man -p' too. Not everything is orange for me but I have some color character which make it hard to read.

2024-07-05-153013_553x329_scrot

It works better with MANPAGER="bat -l man"` 2024-07-05-153233_586x306_scrot

But sometimes the behavior is very strange. 2024-07-05-153334_804x532_scrot

Let me know if you need more info.

Thank you

anurag-roy commented 1 week ago

@flohw Think your issue is different.

Can you check your groff version using

groff -v

And if it's 1.23.0, try adding MANROFFOPT='-c' and that should fix it.

flohw commented 1 week ago

After some experimentations with my env vars, defining this variable worked fine. Thank you

Some explanation if anyone struggle to configure it to their need:

 # For global use across the system (in your bashrc/zshrc)
export MANROFFOPT='-c'
# For local script global useage
MANROFFOPT='-c'
man -P "$MANPAGER' --paging always'" <man entry>
# For online usage
MANROFFOPT='-c' man -P $MANPAGER <man entry>

Note that I haven't tested each one and only based them on my experience. I hope to not have make mistake. :-)