Skip to content

🐛 Delta broken when PAGER env var has arguments #2033

@theturtle32

Description

@theturtle32

Bug Description

Delta fails when the PAGER environment variable contains complex shell commands with arguments, causing "command not found" errors and broken git integration.

Steps to Reproduce

  1. Set a complex PAGER environment variable:

    export PAGER='/bin/sh -c "head -10000 | cat"'
  2. Configure delta as your git pager:

    git config --global core.pager delta
  3. Run any git command that produces diff output:

    git diff --cached
    # or
    git show HEAD

Expected Behavior

Delta should respect the full PAGER command including all arguments and execute it properly to display the formatted diff output.

Actual Behavior

The command fails with multiple "command not found" errors:

line1: command not found
line2: command not found
line3: command not found
...

Each line of the diff output is being interpreted as a shell command instead of being piped through the intended pager.

Root Cause Analysis

The issue appears to be in src/env.rs where delta uses bat::config::get_pager_executable(None) to process the PAGER environment variable. This function strips arguments from the pager command, so:

  • Input: /bin/sh -c "head -10000 | cat"
  • After processing: /bin/sh
  • Result: Shell receives diff lines as commands to execute instead of as stdin

Real-World Impact

This bug significantly affects Cursor IDE users where the AI Agent feature automatically sets:

export PAGER='/bin/sh -c "head -10000 | cat"'

This behavior is not user-configurable in Cursor, making delta completely unusable with git commands in that environment. Users experience constant "command not found" errors when the AI Agent tries to run git commands like git diff --cached.

Environment Details

  • OS: macOS and Linux (and likely other *nix systems)
  • Delta version: Current main branch
  • Shell: Any shell (zsh, bash, etc.)
  • Reproduction: 100% reproducible with complex PAGER commands

Workarounds

Currently, the only workarounds are:

  1. Use DELTA_PAGER instead of PAGER (if the tool allows configuration)
  2. Unset PAGER and let delta use its default
  3. Use a simple pager command without arguments

However, these workarounds are not viable for tools like Cursor IDE that automatically set the PAGER variable.

Additional Context

This issue likely affects any environment or tool that sets sophisticated pager configurations using shell commands with arguments. While delta correctly handles simple pagers like less or bat, it fails with more complex paging strategies.

The problem seems to stem from delta's reliance on bat's pager detection logic, which may be designed for different use cases than what delta requires. There is a more suitable function in bat's source code that returns the full pager command with arguments rather than only the executable itself, but it is not exported publicly.

Suggested Solution Areas

The fix likely needs to:

  1. Preserve the full PAGER command with arguments instead of stripping them
  2. Maintain compatibility with existing simple pager configurations
  3. Continue to handle problematic pagers (more, most) appropriately
  4. Respect the environment variable precedence (DELTA_PAGER > BAT_PAGER > PAGER)

This appears to require reimplementing or modifying the pager detection logic to preserve command arguments while maintaining all existing functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions