Skip to content

Custom Pager support for windows #1453

Closed

Description

@bin101

Is your feature request related to a problem? Please describe.
In my opinion the default pager is very confusing. I really like to use diff-so-fancy or something similar.

Additional context
The custom pager docs are mentioning that you are using a package which has no windows support. Could you (@jesseduffield) clarify which package this is? Maybe there is an alternative in the meantime?

Activity

  1. bin101 commented on Aug 25, 2021

    @bin101
    ContributorAuthor

    This package seems to be PTY, correct?

    There seems to be an alternative named ConPTY for windows since 2018:
    https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/

    And also a go implementation:
    https://github.com/ActiveState/termtest/tree/master/conpty

  2. jesseduffield commented on Sep 27, 2021

    @jesseduffield
    Owner

    Interestingly, we use creack/pty and on that repo there's a PR that appears to be almost across the line which supports conpty: creack/pty#109. So I think we can wait for that to merge and then bump the dependency and hopefully it won't take too much to hook things up (we'd need to update pkg/gui/pty_windows.go or potentially delete that file and have everything go through pkg/gui/pty.go)

  3. tgmpje commented on Jun 21, 2022

    @tgmpje

    Adding a snooze so we get a ping once the PR has been merged.

    @SnoozeThis creack/pty#109

  4. SnoozeThis commented on Jun 21, 2022

    @SnoozeThis

    (https://snoozeth.is/WM8xZZDUIIA) I will wait until creack/pty#109 is merged and then add a comment.

  5. EldinHb commented on Nov 6, 2022

    @EldinHb

    This PR creack/pty#155 looks a bit more lively

  6. EldinHb commented on Nov 7, 2022

    @EldinHb

    Btw, as a workaround you can install WSL on Windows. Setup lazygit how you want it to be in your WSL environment. On your Windows environment go to your project and type the command wsl lazygit. That way WSL will activate lazygit on your current directory even if on Windows and the pagers will work.

    The downside is though that because youre on a mounted drive it can get very slow with large/many files.

  7. SnoozeThis commented on Jan 25, 2023

    @SnoozeThis

    An error occurred while snoozing: Pull request was closed without being merged

  8. pidgeon777 commented on May 22, 2023

    @pidgeon777

    Any update for Windows users running lazygit?

  9. aropele commented on May 23, 2023

    @aropele

    Same problem here. Cannot use lazygit if delta is not supported.

  10. jesseduffield commented on May 23, 2023

    @jesseduffield
    Owner

    Our hope rests on the fate of this PR: creack/pty#155

  11. searleser97 commented on Oct 10, 2023

    @searleser97

    +1 to this

  12. pidgeon777 commented on Oct 11, 2023

    @pidgeon777

    Hopefully this will be fixed / merged.

  13. Kaarel commented on Feb 15, 2024

    @Kaarel

    +1

  14. 23 remaining items

  15. tienlonghungson commented on Nov 5, 2025

    @tienlonghungson

    Thanks. I will let you know if I encounter any issue on Mac.

  16. kaarel-sm commented on Nov 12, 2025

    @kaarel-sm

    I can confirm that the bat script is massively more performant than pwsh #1453 (comment)

  17. sh1Nome commented on Nov 30, 2025

    @sh1Nome

    I was able to run this using a single .bat script with JScript, without relying on pwsh or sed.
    Since I’m not very familiar with .bat scripting or JScript, there might be a better way to write this.
    As others have already shared, it runs faster than pwsh (although I’m not sure how it performs with very large git diffs).

    @if(0)==(0) echo off
    chcp 65001
    setlocal
    
    set "old=%~2"
    set "new=%~5"
    set "target=%~1"
    set "old=%old:\=/%"
    set "new=%new:\=/%"
    
    git --no-pager diff --no-index --no-ext-diff "%old%" "%new%" ^
     | cscript //nologo /u /E:JScript "%~f0" "%old%" "%target%" ^
     | cscript //nologo /u /E:JScript "%~f0" "%new%" "%target%" ^
     | delta --paging=never --width=%LAZYGIT_COLUMNS%
    
    endlocal
    goto :EOF
    @end
    
    var oldStr = WScript.Arguments(0);
    var newStr = WScript.Arguments(1);
    
    var stdin = WScript.StdIn;
    var stdout = WScript.StdOut;
    
    while (!stdin.AtEndOfStream) {
        var line = stdin.ReadLine();
        line = line.split(oldStr).join(newStr);
        stdout.WriteLine(line);
    }
  18. pidgeon777 commented on Nov 30, 2025

    @pidgeon777

    I asked Claude Sonnet 4.5 to look for the most performant solution, and it ended up with this. I'm actually adapting the Perl solution.

    Overview

    When configuring LazyGit's externalDiffCommand on Windows, three main approaches exist for processing git diff output before piping to delta. This comparison evaluates their performance, reliability, and portability.

    Architecture Comparison

    Aspect Perl Solution Sed Solution JScript Solution
    Dependencies Requires perl in PATH Requires sed in PATH None (native Windows)
    Pipe Architecture Single pipe chain Single pipe chain Double pipe chain
    Processing Speed ~100 MB/s ~50 MB/s ~10-20 MB/s
    Startup Overhead ~5-10ms ~10-20ms ~200-400ms (2× cscript)
    Total Time (50KB diff) ~15ms ~30ms ~450ms
    Special Char Handling Automatic escape (\Q\E) No escape (bug) Safe (split/join)
    Portability ~70% (if Git for Windows) ~95% (if Git for Windows) 100% (always available)

    Solution Details

    🥇 Perl Solution (Recommended)

    @echo off
    set "old=%~2"
    set "new=%~5"
    set "target=%~1"
    set "old=%old:\=/%"
    set "new=%new:\=/%"
    
    git --no-pager diff --no-index --no-ext-diff "%old%" "%new%" | ^
    perl -pe "s|\Q%old%\E|%target%|g;s|\Q%new%\E|%target%|g" | ^
    delta --paging=never --width=%LAZYGIT_COLUMNS% --side-by-side --line-numbers

    Strengths:

    • Fastest performance - minimal overhead, efficient text processing
    • Robust escaping - \Q...\E automatically escapes regex metacharacters
    • Clean architecture - single efficient pipe chain
    • Handles edge cases - correctly processes paths with special characters like file[test].txt, ver.2.0, etc.
    • Widely available - included with Git for Windows standard installation

    Limitations:

    • Requires perl in PATH (verify with where perl in cmd)

    Best for: Production use when Git for Windows is installed (most common scenario)


    🥈 JScript Solution (Universal Fallback)

    @if(0)==(0) echo off
    chcp 65001
    setlocal
    
    set "old=%~2"
    set "new=%~5"
    set "target=%~1"
    set "old=%old:\=/%"
    set "new=%new:\=/%"
    
    git --no-pager diff --no-index --no-ext-diff "%old%" "%new%" ^
     | cscript //nologo /u /E:JScript "%~f0" "%old%" "%target%" ^
     | cscript //nologo /u /E:JScript "%~f0" "%new%" "%target%" ^
     | delta --paging=never --width=%LAZYGIT_COLUMNS%
    
    endlocal
    goto :EOF
    @end
    
    var oldStr = WScript.Arguments(0);
    var newStr = WScript.Arguments(1);
    
    var stdin = WScript.StdIn;
    var stdout = WScript.StdOut;
    
    while (!stdin.AtEndOfStream) {
        var line = stdin.ReadLine();
        line = line.split(oldStr).join(newStr);
        stdout.WriteLine(line);
    }

    Strengths:

    • Zero dependencies - cscript is native to Windows, always available
    • Guaranteed compatibility - works on any Windows system
    • Safe string replacement - split().join() handles special characters correctly
    • Explicit UTF-8 - chcp 65001 ensures proper encoding

    Limitations:

    • Significantly slower - 30× slower than Perl for typical diffs (~450ms vs ~15ms)
    • Double overhead - requires two separate cscript invocations
    • Inefficient architecture - two replacement passes instead of one

    Best for: Systems without Git for Windows, guaranteed portability, automated deployments


    🥉 Sed Solution (Not Recommended)

    @echo off
    
    set "old=%~2"
    set "new=%~5"
    set "target=%~1"
    set "old=%old:\=/%"
    set "new=%new:\=/%"
    
    git --no-pager diff --no-index --no-ext-diff "%old%" "%new%" | ^
    sed -e "s|%old%|%target%|g" -e "s|%new%|%target%|g" | ^
    delta --side-by-side --line-numbers --paging=never --width=%LAZYGIT_COLUMNS% ^
      --hyperlinks --hyperlinks-file-link-format="lazygit-edit://{path}:{line}"

    Strengths:

    • Single pipe architecture
    • Available with Git for Windows

    Critical Issues:

    • No regex escaping - special characters in paths are interpreted as regex patterns
    • Fails with paths containing:
      • Square brackets: project[beta] → interpreted as character class
      • Dots: file.backup → matches any character instead of literal dot
      • Parentheses: (old) → interpreted as capture group
      • Dollar signs: $temp → interpreted as end-of-line anchor
    • Unusable hyperlinks - lazygit-edit:// protocol not supported by LazyGit
    • Encoding issues - sed on Windows has inconsistent UTF-8 handling

    Example failure scenario:

    Path: C:/project-v2.0[beta]/file.backup.txt
    Result: Incorrect replacements due to regex interpretation
    

    Best for: Nothing - use Perl or JScript instead


    Performance Benchmark

    Tested with typical 50KB diff output:

    ┌──────────┬─────────────┬───────────────┬─────────────┐
    │ Solution │ Overhead    │ Processing    │ Total Time  │
    ├──────────┼─────────────┼───────────────┼─────────────┤
    │ Perl     │ ~10ms       │ ~5ms          │ ~15ms       │
    │ JScript  │ ~400ms      │ ~50ms         │ ~450ms      │
    │ Sed      │ ~20ms       │ ~10ms         │ ~30ms*      │
    └──────────┴─────────────┴───────────────┴─────────────┘
    
    * When it works correctly (no special characters in paths)
    

    Decision Matrix

    Choose Perl if:

    • ✅ You have Git for Windows installed (standard setup)
    • ✅ You need best performance
    • ✅ You work with paths containing special characters
    • ✅ You want production-grade reliability

    Choose JScript if:

    • ✅ You need guaranteed Windows compatibility
    • ✅ You can't install additional tools
    • ✅ Performance is not critical (~0.5s delay acceptable)
    • ✅ You need a self-contained solution

    Avoid Sed because:

    • ❌ Critical bug with special characters in paths
    • ❌ Unreliable on Windows systems
    • ❌ No advantages over Perl or JScript

    Verification and Installation

    Check if Perl is available:

    where perl

    If Perl is found → Use the Perl solution (recommended)

    If Perl is not found → Use the JScript solution (universal fallback)

    LazyGit Configuration:

    git:
      paging:
        externalDiffCommand: 'C:/path/to/git-diff.bat'

    Conclusion

    The Perl solution is the clear winner for standard Windows development environments with Git for Windows. It offers the best combination of performance, reliability, and robustness.

    The JScript solution serves as an excellent universal fallback, trading performance for guaranteed compatibility.

    The Sed solution should be avoided due to its critical handling issues with regex metacharacters in file paths, making it unreliable for real-world usage.

  19. acebyronehalilistartanimation commented on Jan 12, 2026

    @acebyronehalilistartanimation

    I don't know why but I'm having trouble getting custom pagers to work.

    This is my setup:
    File: C:\Users\aceby\lazygit-pager.bat

    @echo off
    
    set "old=%~2"
    set "new=%~5"
    set "target=%~1"
    set "old=%old:\=/%"
    set "new=%new:\=/%"
    
    git --no-pager diff --no-index --no-ext-diff "%old%" "%new%"^
     | sed -e "s|%old%|%target%|g" -e "s|%new%|%target%|g"^
     | delta --paging=never --width=%LAZYGIT_COLUMNS%

    File: C:\Users\aceby\AppData\Local\lazygit\config.yml

    quitOnTopLevelReturn: true
    git:
      pagers:
        - externalDiffCommand: "C:/Users/aceby/lazygit-pager.bat"
    os:
      editPreset: 'nvim'

    I have sed and delta installed already.

    A bit of a bizarre behavior I found: if I change externalDiffCommand to a file that does not exist, lazygit runs as normal with the default pager. This leads me to believe that my issue is a problem with the bat file not being read at all by lazygit.

    I'd appreciate some help bc the default pager is so uglyy

    EDIT: I solved the problem by using paging instead of pagers and removing the "-" in front of externalDiffCommand

  20. lucaspimentel commented on Jan 14, 2026

    @lucaspimentel

    @acebyronehalilistartanimation

    EDIT: I solved the problem by using paging instead of pagers and removing the "-" in front of externalDiffCommand

    Which version of lazygit are you using? Support for multiple pagers (using the pagers array in the configuration file) was added in v0.56.0.

  21. acebyronehalilistartanimation commented on Jan 15, 2026

    @acebyronehalilistartanimation

    @acebyronehalilistartanimation

    EDIT: I solved the problem by using paging instead of pagers and removing the "-" in front of externalDiffCommand

    Which version of lazygit are you using? Support for multiple pagers (using the pagers array in the configuration file) was added in v0.56.0.

    Hmm, that's bizarre. I'm using v0.58.0

  22. leotorrez commented on Apr 27, 2026

    @leotorrez

    Can confirm that this issue persists in 0.61.1. Furthermore, when scrolling on the list of files the diff script runs properly but soon as I press enter it goes back to the default lazygit look for diffs

  23. seanmartinsmith commented on Jun 29, 2026

    @seanmartinsmith

    heads-up for folks watching this: there's a windows-pty branch on the repo (by @stefanhaller) adding ConPTY-based pager support, and i built + ran it on real windows 11 - native build, go 1.26.3, with delta 0.19.2 as the pager.

    it works. delta renders correctly in lazygit's diff panel through ConPTY - line numbers, themed file/hunk headers, side-by-side, no leaked escape-sequence junk. for contrast i ran the exact same flow off current master and the pager's ignored entirely there (you just get raw single-column git diff --color=always), so the branch genuinely fixes this.

    also: the cmd_obj_runner pty path (a custom command with output: logWithPty) kicks off through the pty with no hang, and panel switching + navigation + exit all behave normally.

    one thing that looks like a bug but isn't - a stray Δ before modified filenames is just delta's default file-modified-label, reproduces with git show | delta outside lazygit.

    didn't test credential prompts over the pty (my remotes are all SSH). happy to test more on windows if it's useful.

  24. stefanhaller commented on Jun 29, 2026

    @stefanhaller
    Collaborator

    @seanmartinsmith Don't use this branch yet, it's unfinished. I'll let you all know when it's ready, shouldn't take too long.

  25. stefanhaller commented on Jun 30, 2026

    @stefanhaller
    Collaborator

    PR is here: #5740. Please test this thoroughly before I merge it.

  26. seanmartinsmith commented on Jul 1, 2026

    @seanmartinsmith

    PR is here: #5740. Please test this thoroughly before I merge it.

    will be able to test tomorrow - thank you!

  27. added a commit that references this issue on Jul 3, 2026
    16d773f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions