sharkdp/bat

bat breaks pasting into less `/pattern` search with incremental search enabled

Closed this issue · 2 comments

What steps will reproduce the bug?

  1. echo ss > data
  2. bat --pager='less -R --incsearch' data (these are bat's default flags, but with --incsearch for incremental search, without -F so less stays open, and without -X as I'm using a modern version of less)
  3. Copy ss into the clipboard
  4. Press / then paste

What happens?

less prompts for a log file (as if you ran the s command). It seems like bat is causing less to interpret the pasted text as separate commands.

When data only contains ss, this always happens. If you edit the data file to add a sufficient number of trailing newlines, the problem happens only sometimes.

What did you expect to happen instead?

After pressing / to start a search, pasting text should search for it.

How did you install bat?

Homebrew


bat version and environment

Software version

bat 0.25.0

Operating system

  • OS: macOS 15.6 Sequoia
  • Kernel: 24.6.0

Command-line

bat '--pager=less -R --incsearch' foo --diagnostic 

Environment variables

BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=truecolor
LANG=en_CA.UTF-8
LC_ALL=<not set>
LESS=<not set>
MANPAGER='sh -c '\''col -bx | bat --language=man --style=plain'\'''
NO_COLOR=<not set>
PAGER=<not set>
SHELL=/usr/local/bin/fish
TERM=xterm-ghostty
XDG_CACHE_HOME=<not set>
XDG_CONFIG_HOME=<not set>

System Config file

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

Config file

--theme-light="Catppuccin Latte"
--theme-dark="Catppuccin Mocha"

Custom assets metadata

bat_version: 0.25.0
creation_time:
  secs_since_epoch: 1752543638
  nanos_since_epoch: 642619000

Custom assets

  • metadata.yaml, 97 bytes
  • syntaxes.bin, 969578 bytes
  • themes.bin, 58252 bytes

Compile time information

  • Profile: release
  • Target triple: x86_64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: cmpxchg16b,fxsr,pclmulqdq,popcnt,sse,sse2,sse3,sse4.1,sse4.2,ssse3
  • Host: x86_64-apple-darwin

Less version

> less --version 
less 679 (PCRE2 regular expressions)
Copyright (C) 1984-2025  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

FWIW I can't reproduce this with less 590 on linux. But I could guess that it is to do with line buffering if it works for you when the file has trailing new lines. Does the same behavior occur with cat data | less -R --incsearch?

Does the same behavior occur with cat data | less -R --incsearch?

Yeah, it does. Not a problem related to bat, then.

Sorry for the noise, I thought I already ruled out a less bug, but evidently I did something wrong.