-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
--no-paging seems to still imply wrapping but only when output is piped #3660
Description
What steps will reproduce the bug?
cat foo | bat --no-paging --color=always -lzshcat foo | bat --no-paging --color=always -lzsh | less -+J
What happens?
The output is different (in most cases) as --terminal-width is not being specified explicitly.
What did you expect to happen instead?
I would not expect it to wrap only when piped.
Preferably, it shouldn't ever wrap when piped, as wrapping is the job of the pager.
I have a similar use case as is described in #3526 (fixed in ad60801).
Note that this issue does not occur when --wrap=character is not included in the config file.
However, I would only expect --wrap=character to affect the output that bat is currently displaying, as in, when being used without a pager, or with a configured/built-in pager.
Presently, bat will only wrap text when --pager=never / --no-pager is passed if it is being piped elsewhere. This seems counterintuitive to what one would normally expect, as in, if --no-pager implies bat should not apply wrapping, then shouldn't that also apply to when bat is piped somewhere?
Ideally, I would prefer bat to apply wrapping without a pager when --no-pager is passed if it is not being piped, and I do believe that this would be the most intuitive use-case.
For example, if it is not being piped, one can assume a lack of a pipe means a lack of a READNULLCMD, which means their output will be displayed as-is, therefor, it should be wrapped.
Inversely, if one is piping the output, that must imply that whatever they are piping it to will format it better for the purpose of being displayed, or they want to embed the output inside something like fzf.
A larger issue with --wrap=character when piping is noticed when the width at which it pipes seemingly does not respect $COLUMNS nor $TERMINALWIDTH / $TERMWIDTH / $TERM_WIDTH?
It also does not correctly calculate the current width of my terminal when it is piped, resulting in a hard wrap at 80 characters, which is quite unreasonable when I'm piping the output to be used elsewhere in fzf / a terminal widget and I expect it to fit inside my terminal (only to find out it is assumed that my terminal is only 80 characters wide).
Another reason against wrapping when using --wrap=character in a pipe, is that if I need to pipe the output of bat to tr or sed, I do not want that output to be formatted any differently than when I am running the command without a pipe.
I expect it to be exactly the same.
There could be an argument for changing the current behavior to respect $COLUMNS by default, as well as changing --wrap=character when it is contained inside the config file to not affect pipes, however, if there is a strong enough use case for affecting piping when --wrap=character is specified explicitly on a CLI, I would be okay with that, but I cannot think of a reason why you would want it to do so.
If you'd prefer the config file to not break parity in terms of behavior with being explicitly specified on a CLI that is also reasonable, so long as piped output is not affected at the end of the day.
How did you install bat?
Built from source.
bat version and environment
bat 0.26.1 (v0.25.0-604-ga500fb23)
Software version
bat 0.26.1 (v0.25.0-604-ga500fb23)
Operating system
- OS: macOS 14.7.6 Sonoma
- Kernel: 23.6.0
Command-line
./target/release/bat -lrust -f --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=<not set>
LANG=en_US.UTF-8
LC_ALL=<not set>
LESS='-Q -FReSiAMKJ -#1 -x4 -j10 --match-shift .3 --use-color --status-line --status-col-width=1 --search-options=W --SILENT'
MANPAGER=<not set>
NO_COLOR=<not set>
PAGER=<not set>
SHELL=/opt/homebrew/bin/zsh
TERM=xterm-256color
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
# This is `bat`s configuration file. Each line either contains a comment or
# a command-line option that you want to pass to `bat` by default. You can
# run `bat --help` to get a list of all possible configuration options.
# Specify desired highlighting theme (e.g. "TwoDark"). Run `bat --list-themes`
# for a list of all available themes
#--theme="TwoDark"
# Enable this to use italic text on the terminal. This is not supported on all
# terminal emulators (like tmux, by default):
--italic-text=always
# Uncomment the following line to disable automatic paging:
#--paging=never
# Uncomment the following line if you are using less version >= 551 and want to
# enable mouse scrolling support in `bat` when running inside tmux. This might
# disable text selection, unless you press shift.
#
# Exclude: -J (status col) -W (hilite unread)
#--pager="less -Q -FRSiAMK -#1 -x4 -j10 --match-shift .3 --wordwrap --use-color --search-options=W --status-col-width=0 --exit-follow-on-close --no-search-headers --no-edit-warn --no-keypad --no-vbell --show-preproc-errors -+S -+J "
--pager="less -Q -FRSiAMK -#1 -x4 -j10 --match-shift .3 --wordwrap --use-color --search-options=W --status-col-width=0 --exit-follow-on-close --no-search-headers --no-edit-warn --no-keypad --no-vbell --show-preproc-errors --+status-column"
# -E --redraw-on-quit (exit on EoF and keep displayed contents)
#--pager="less -- +--exit-follow-on-close +--wait-follow-on-close +--no-keypad +--no-search-headers +--redraw-on-quit +--save-marks +-zn200 +-bn24"
# --redraw-on-quit --no-paste --MOUSE
# -FRSiWJAM -#1 -x4 -j10 --match-shift .3 --use-color --status-line --status-col-width=1 --search-options=W -DWMk
# Syntax mappings: map a certain filename pattern to a language.
# Example 1: use the C++ syntax for Arduino .ino files
# Example 2: Use ".gitignore"-style highlighting for ".ignore" files
#--map-syntax "*.ino:C++"
--map-syntax "*.go:Go"
--map-syntax "main.go:Go"
--map-syntax ".ignore:Git Ignore"
--map-syntax "Caddyfile:nginx"
--map-syntax "Corefile:nginx"
--map-syntax "rgx:Regular Expression"
--map-syntax "regex:Regular Expression"
--theme-dark=OneHalfDark
--theme-dark=1337
--theme-dark='Monokai Extended Origin'
#--decorations=auto
#--style=full,-grid,-header-filename,-header-filesize
--style=full,-grid,-header,-header-filesize
#--style=rule,numbers,snip,changes
#--style=full,grid
--tabs=4
--wrap=character
#--chop-long-lines
#--terminal-width="$(tput cols)"
Custom assets metadata
bat_version: 0.26.1
creation_time:
secs_since_epoch: 1774117191
nanos_since_epoch: 45520000
Custom assets
- bat-caches.tar.xz, 1427092 bytes
- metadata.yaml, 96 bytes
- syntaxes.bin, 1812839 bytes
- themes.bin, 58318 bytes
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 692 (PCRE2 regular expressions)
Copyright (C) 1984-2026 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