Fix: preserve arguments in complex PAGER commands #2034
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.
Description
Delta was incorrectly stripping arguments from complex
PAGER
environment variable commands, causing failures when used with tools that set sophisticated pager configurations.Problem
The issue occurred because delta was using
bat::config::get_pager_executable(None)
to process thePAGER
environment variable. This function was designed to return only the executable path, stripping all arguments from the command. For simple pagers likeless
orbat
, this worked fine. However, for complex shell commands like/bin/sh -c "head -10000 | cat"
, this caused serious problems:/bin/sh -c "head -10000 | cat"
became just/bin/sh
/bin/sh
received delta's output, it tried to execute each line as a shell commandReal-world Impact
This bug particularly affected users of Cursor IDE's AI Agent feature, which automatically sets:
This configuration is not user-configurable in Cursor, causing git commands like
git diff --cached
to fail consistently with "command not found" errors when delta was configured as the git pager.Root Cause
The problem was in
src/env.rs
where delta called:This function was designed to extract just the executable name for validation purposes, not to preserve the full command with arguments for execution.
Solution
The fix reimplements bat's pager detection logic locally in delta to:
more
,most
) withless
DELTA_PAGER
>BAT_PAGER
>PAGER
)Changes Made
bat::config::get_pager_executable(None)
with customget_pager_from_env()
functionTesting
The fix includes extensive test coverage:
/bin/sh -c "head -10000 | cat"
)less -R -F -X
)more
→less
)DELTA_PAGER
vsPAGER
)Compatibility
This fix maintains full backward compatibility:
less
,bat
) work unchangedmore
,most
) still get replaced withless
The fix specifically resolves the Cursor IDE integration issue while improving delta's robustness for any environment that uses complex pager configurations.
Resolves #2033