Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bat syntax highlighting doesn't play nicely with backslashes #2803

Closed
cohml opened this issue Dec 14, 2023 · 6 comments
Closed

Bat syntax highlighting doesn't play nicely with backslashes #2803

cohml opened this issue Dec 14, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@cohml
Copy link

cohml commented Dec 14, 2023

Sorry for disregarding parts of the default issue template. I think the following examples should speak for themselves and be easily reproducible. All examples generated with iTerm2 on MacOS Sonoma 14.1.2 and RedHat Linux.

❯ bat --version
bat 0.24.0
❯ echo "curl" | BAT_OPTS= bat --paging=never --style=plain
curl
❯ echo "curl foo" | BAT_OPTS= bat --paging=never --style=plain
curl foo
❯ echo "\curl foo" | BAT_OPTS= bat --paging=never --style=plain

❯ echo "\curl" | BAT_OPTS= bat --paging=never --style=plain

❯ echo "curl \foo" | BAT_OPTS= bat --paging=never --style=plain
curl
     oo
❯ echo "curl \\foo" | BAT_OPTS= bat --paging=never --style=plain
curl
     oo
❯ echo "curl \\\foo" | BAT_OPTS= bat --paging=never --style=plain
curl \foo

I suspect \ sometimes confuses bat into perhaps incorrectly interpreting things as control characters?

How did you install bat?

Homebrew.


bat version and environment

❯ bat --diagnostic

Software version

bat 0.24.0

Operating system

macOS 14.1.2 (Darwin 23.1.0)

Command-line

/Users/<redacted>/.df/lib/bin/bat --diagnostic

Environment variables

SHELL=/bin/zsh
PAGER=less
LESS=-R
LANG=en_US.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='--italic-text=always --pager='\''less --chop-long-lines --header=1 --jump-target=3 --line-num-width=0               --LONG-PROMPT --no-number-headers --shift=4 --status-column --use-color --color=HGk --color=NGk'\'' --style=changes,header-filename,rule,snip --theme=TwoDark --wrap=never'
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 --theme=Monokai\ Extended'\'''

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//.config/bat/config': No such file or directory (os error 2).

Custom assets metadata

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

Custom assets

'/Users//.cache/bat' not found

Compile time information

  • Profile: release
  • Target triple: aarch64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: aarch64
  • Pointer width: 64
  • Endian: little
  • CPU features: aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh
  • Host: aarch64-apple-darwin

Less version

> less --version
less 633 (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
@cohml cohml added the bug Something isn't working label Dec 14, 2023
@mxaddict
Copy link
Contributor

mxaddict commented Dec 15, 2023

I tried the samples that you have, and can't seem to replicate, maybe it's shell related?

image

@mxaddict
Copy link
Contributor

I'm using same bat version:

mxaddict@mxaddict-pc:~ on ☁️  (us-west-2)
❯ bat --version
bat 0.24.0 (fc954685)

@keith-hall
Copy link
Collaborator

presumably those same examples would look the same even without piping into bat... I see something similar on Linux with just echo -e "\curl"

@cohml
Copy link
Author

cohml commented Dec 16, 2023

Wait, you're right!! Even without bat I get this same behavior. TBH I'm embarrassed I didn't even think to test that before uploading this issue... I guess I will close it!

But I must admit, I'm curious why @keith-hall and I see the same behavior (even with just echo and no bat) while @mxaddict does not. We must have some differences in our environments. I am not knowingly doing anything to echo - maybe @mxaddict is? (e.g., setting alias echo="echo -E")

@cohml cohml closed this as completed Dec 16, 2023
@mxaddict
Copy link
Contributor

Wait, you're right!! Even without bat I get this same behavior. TBH I'm embarrassed I didn't even think to test that before uploading this issue... I guess I will close it!

But I must admit, I'm curious why @keith-hall and I see the same behavior (even with just echo and no bat) while @mxaddict does not. We must have some differences in our environments. I am not knowingly doing anything to echo - maybe @mxaddict is? (e.g., setting alias echo="echo -E")

I don't have an echo alias, but I am running fish as my shell, I think it handles \ a little differently compared to bash/zsh

@cohml
Copy link
Author

cohml commented Dec 16, 2023

Aha, that could be it. Fish vs zsh is definitely a nontrivial difference.

Anyway, this behavior is annoying, but not bat's fault. I'm amazed I hadn't discovered it until now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants