Repository navigation
Keep backslashes in the config file and BAT_OPTS on Windows - #4164
Merged
keith-hall merged 2 commits intoNov 29, 2026
Merged
Conversation
The config file and BAT_OPTS were split with shell_words, which treats a backslash as an escape, so --pager=C:\tools\less.exe became C:toolsless.exe. Split them with the same function as the pager command, which keeps backslashes on Windows since sharkdp#4104. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
cindykrafft
pushed a commit
to cindykrafft/bat
that referenced
this pull request
Nov 29, 2026
Resolve the CHANGELOG conflict with sharkdp#4164 by keeping both entries. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#4104 stopped
shell_wordsfrom eating the backslashes inBAT_PAGER/PAGER/--pageron Windows. The config file and
BAT_OPTSstill go throughshell_words::split, so thesame value written there is still broken. With a config file containing
bat prints
while
BAT_PAGER=C:\Windows\System32\more.comworks.Reproduction (Windows 11, Git Bash, current master c758b4d)
BAT_OPTS='--pager=C:\Windows\System32\more.com'shows the same problem as the config file.Root cause
Each line of the config file (and the
BAT_OPTSvalue) is split byget_args_from_strinsrc/bin/bat/config.rswithshell_words::split. That function follows POSIX rules, where\escapes the next character outside of quotes, so
C:\tools\less.exebecomesC:toolsless.exebefore the pager code sees it. #4104 fixed this in
pager::split_command, but the config fileis split earlier and separately.
Fix
The config file and
BAT_OPTSare now split by the same function as the pager command(
pager::split_command), exposed to the binary asbat::config::split_arguments. It is gatedthe same way as
bat::config::get_pager_executable. On Windows,\stays literal and singleand double quotes still group words. On other platforms nothing changes, because
split_commandstill callsshell_words::splitthere.On Windows, the change is the same one #4104 made for
BAT_PAGER. A backslash outside quotesis no longer an escape:
a\ bgives two words, and\"no longer gives a literal quote.Quoting (
"a b",'a"b') still works. A config that worked around the bug by doublingbackslashes (
C:\\tools\\less.exe) still works, because Windows treats the doubledseparators as one.
Tests
config::windows_paths_keep_backslashes(#[cfg(windows)], insrc/bin/bat/config.rs). It fails without the fix:cargo test --lockedon Windows 11 (x86_64-pc-windows-msvc): all suites pass(lib 158, bin 11, integration 290 passed / 2 ignored, snapshot 27, doc tests 3 passed / 2 ignored).
cargo fmt -- --check: clean.cargo clippy --locked --all-targets --all-features -- -D warnings: exit 0, no warnings.cargo check --locked --lib --no-default-features --features regex-onig: exit 0 (one existing dead-code warning insrc/printer.rs, not from this change).more.comwithout the warning,for both the config file and
BAT_OPTS.CHANGELOG
Added an entry under "Bugfixes".
AI disclosure
This change was prepared with Claude Code (an AI coding assistant), which reproduced the bug and ran the tests above on my Windows machine. I reviewed the change before submitting.
🤖 Generated with Claude Code