Skip to content

Commit c31b604

Browse files
authored
Document a workaround for using custom pagers on Windows (#4941)
Custom pagers are not supported on Windows, because using a pager in git requires the git command to run in a PTY, but the PTY package we are using doesn't support Windows. However, there's a workaround to use a custom pager by using a Powershell script configured as an external diff command. Document this in the `Custom_Pagers.md` document, and export a `LAZYGIT_COLUMNS` environment variable to allow such scripts to work better.
2 parents 4b59f98 + 2abd76e commit c31b604

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

docs/Custom_Pagers.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Lazygit supports custom pagers, [configured](/docs/Config.md) in the config.yml file (which can be opened by pressing `e` in the Status panel).
44

5-
Support does not extend to Windows users, because we're making use of a package which doesn't have Windows support.
5+
Support does not extend to Windows users, because we're making use of a package which doesn't have Windows support. However, see [below](#emulating-custom-pagers-on-windows) for a workaround.
66

77
## Default:
88

@@ -84,3 +84,30 @@ git:
8484
```
8585

8686
This can be useful if you also want to use it for diffs on the command line, and it also has the advantage that you can configure it per file type in `.gitattributes`; see https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
87+
88+
## Emulating custom pagers on Windows
89+
90+
There is a trick to emulate custom pagers on Windows using a Powershell script configured as an external diff command. It's not perfect, but certainly better than nothing. To do this, save the following script as `lazygit-pager.ps1` at a convenient place on your disk:
91+
92+
```pwsh
93+
#!/usr/bin/env pwsh
94+
95+
$old = $args[1].Replace('\', '/')
96+
$new = $args[4].Replace('\', '/')
97+
$path = $args[0]
98+
git diff --no-index --no-ext-diff $old $new
99+
| %{ $_.Replace($old, $path).Replace($new, $path) }
100+
| delta --width=$env:LAZYGIT_COLUMNS
101+
```
102+
103+
Use the pager of your choice with the arguments you like in the last line of the script. Personally I wouldn't want to use lazygit anymore without delta's `--hyperlinks --hyperlinks-file-link-format="lazygit-edit://{path}:{line}"` args, see [above](#delta).
104+
105+
In your lazygit config, use
106+
107+
```yml
108+
git:
109+
paging:
110+
externalDiffCommand: "C:/wherever/lazygit-pager.ps1"
111+
```
112+
113+
The main limitation of this approach compared to a "real" pager is that renames are not displayed correctly; they are shown as if they were modifications of the old file. (This affects only the hunk headers; the diff itself is always correct.)

pkg/gui/pty_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gui
22

33
import (
4+
"fmt"
45
"os/exec"
56

67
"github.com/jesseduffield/gocui"
@@ -11,5 +12,6 @@ func (gui *Gui) onResize() error {
1112
}
1213

1314
func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
15+
cmd.Env = append(cmd.Env, fmt.Sprintf("LAZYGIT_COLUMNS=%d", view.InnerWidth()))
1416
return gui.newCmdTask(view, cmd, prefix)
1517
}

0 commit comments

Comments
 (0)