Skip to content

Commit 5812466

Browse files
authored
Support multiple pagers (#4953)
Allow configuring an array of pagers, and cycling through them with the `|` key (mnemonic: we are piping the output through something). I find this useful for switching between delta (which I prefer most of the time) and difftastic (which occasionally produces better output for certain kinds of changes). It could also be used to switch between delta in inline mode and in side-by-side mode.
2 parents 1c87776 + 32bf6d6 commit 5812466

31 files changed

+420
-134
lines changed

docs/Config.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,30 @@ gui:
319319

320320
# Config relating to git
321321
git:
322+
# Array of pagers. Each entry has the following format:
323+
#
324+
# # Value of the --color arg in the git diff command. Some pagers want
325+
# # this to be set to 'always' and some want it set to 'never'
326+
# colorArg: "always"
327+
#
328+
# # e.g.
329+
# # diff-so-fancy
330+
# # delta --dark --paging=never
331+
# # ydiff -p cat -s --wrap --width={{columnWidth}}
332+
# pager: ""
333+
#
334+
# # e.g. 'difft --color=always'
335+
# externalDiffCommand: ""
336+
#
337+
# # If true, Lazygit will use git's `diff.external` config for paging.
338+
# # The advantage over `externalDiffCommand` is that this can be
339+
# # configured per file type in .gitattributes; see
340+
# # https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
341+
# useExternalDiffGitConfig: false
342+
#
322343
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md
323-
paging:
324-
# Value of the --color arg in the git diff command. Some pagers want this to be
325-
# set to 'always' and some want it set to 'never'
326-
colorArg: always
327-
328-
# e.g.
329-
# diff-so-fancy
330-
# delta --dark --paging=never
331-
# ydiff -p cat -s --wrap --width={{columnWidth}}
332-
pager: ""
333-
334-
# e.g. 'difft --color=always'
335-
externalDiffCommand: ""
336-
337-
# If true, Lazygit will use git's `diff.external` config for paging. The
338-
# advantage over `externalDiffCommand` is that this can be configured per file
339-
# type in .gitattributes; see
340-
# https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
341-
useExternalDiffGitConfig: false
344+
# for more information.
345+
pagers: []
342346

343347
# Config relating to committing
344348
commit:
@@ -638,6 +642,7 @@ keybinding:
638642
prevTab: '['
639643
nextScreenMode: +
640644
prevScreenMode: _
645+
cyclePagers: '|'
641646
undo: z
642647
redo: Z
643648
filteringMenu: <c-s>

docs/Custom_Pagers.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ Lazygit supports custom pagers, [configured](/docs/Config.md) in the config.yml
44

55
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

7-
## Default:
7+
Multiple pagers are supported; you can cycle through them with the `|` key. This can be useful if you usually prefer a particular pager, but want to use a different one for certain kinds of diffs.
8+
9+
Pagers are configured with the `pagers` array in the git section; here's an example for a multi-pager setup:
810

911
```yaml
1012
git:
11-
paging:
12-
colorArg: always
13+
pagers:
14+
- pager: delta --dark --paging=never
15+
- pager: ydiff -p cat -s --wrap --width={{columnWidth}}
16+
colorArg: never
17+
- externalDiffCommand: difft --color=always
1318
```
1419
15-
the `colorArg` key is for whether you want the `--color=always` arg in your `git diff` command. Some pagers want it set to `always`, others want it set to `never`.
20+
The `colorArg` key is for whether you want the `--color=always` arg in your `git diff` command. Some pagers want it set to `always`, others want it set to `never`. The default is `always`, since that's what most pagers need.
1621

1722
## Delta:
1823

1924
```yaml
2025
git:
21-
paging:
22-
colorArg: always
23-
pager: delta --dark --paging=never
26+
pagers:
27+
- pager: delta --dark --paging=never
2428
```
2529

2630
![](https://i.imgur.com/QJpQkF3.png)
@@ -31,9 +35,8 @@ A cool feature of delta is --hyperlinks, which renders clickable links for the l
3135

3236
```yaml
3337
git:
34-
paging:
35-
colorArg: always
36-
pager: diff-so-fancy
38+
pagers:
39+
- pager: diff-so-fancy
3740
```
3841

3942
![](https://i.imgur.com/rjH1TpT.png)
@@ -44,9 +47,9 @@ git:
4447
gui:
4548
sidePanelWidth: 0.2 # gives you more space to show things side-by-side
4649
git:
47-
paging:
48-
colorArg: never
49-
pager: ydiff -p cat -s --wrap --width={{columnWidth}}
50+
pagers:
51+
- colorArg: never
52+
pager: ydiff -p cat -s --wrap --width={{columnWidth}}
5053
```
5154

5255
![](https://i.imgur.com/vaa8z0H.png)
@@ -61,8 +64,8 @@ These can be used in lazygit by using the `externalDiffCommand` config; in the c
6164

6265
```yaml
6366
git:
64-
paging:
65-
externalDiffCommand: difft --color=always
67+
pagers:
68+
- externalDiffCommand: difft --color=always
6669
```
6770

6871
The `colorArg` and `pager` options are not used in this case.
@@ -71,16 +74,16 @@ You can add whatever extra arguments you prefer for your difftool; for instance
7174

7275
```yaml
7376
git:
74-
paging:
75-
externalDiffCommand: difft --color=always --display=inline --syntax-highlight=off
77+
pagers:
78+
- externalDiffCommand: difft --color=always --display=inline --syntax-highlight=off
7679
```
7780

7881
Instead of setting this command in lazygit's `externalDiffCommand` config, you can also tell lazygit to use the external diff command that is configured in git itself (`diff.external`), by using
7982

8083
```yaml
8184
git:
82-
paging:
83-
useExternalDiffGitConfig: true
85+
pagers:
86+
- useExternalDiffGitConfig: true
8487
```
8588

8689
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.
@@ -106,8 +109,8 @@ In your lazygit config, use
106109

107110
```yml
108111
git:
109-
paging:
110-
externalDiffCommand: "C:/wherever/lazygit-pager.ps1"
112+
pagers:
113+
- externalDiffCommand: "C:/wherever/lazygit-pager.ps1"
111114
```
112115

113116
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.)

docs/keybindings/Keybindings_en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2424
| `` R `` | Refresh | Refresh the git state (i.e. run `git status`, `git branch`, etc in background to update the contents of panels). This does not run `git fetch`. |
2525
| `` + `` | Next screen mode (normal/half/fullscreen) | |
2626
| `` _ `` | Prev screen mode | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | Cancel | |
2829
| `` ? `` | Open keybindings menu | |
2930
| `` <c-s> `` | View filter options | View options for filtering the commit log, so that only commits matching the filter are shown. |

docs/keybindings/Keybindings_ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味
2424
| `` R `` | 更新 | Gitの状態を更新します(`git status``git branch`などをバックグラウンドで実行してパネルの内容を更新します)。これは`git fetch`を実行しません。 |
2525
| `` + `` | 次の画面モード(通常/半分/全画面) | |
2626
| `` _ `` | 前の画面モード | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | キャンセル | |
2829
| `` ? `` | キーバインディングメニューを開く | |
2930
| `` <c-s> `` | フィルターオプションを表示 | コミットログのフィルタリングオプションを表示し、フィルタに一致するコミットのみを表示します。 |

docs/keybindings/Keybindings_ko.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2424
| `` R `` | 새로고침 | Refresh the git state (i.e. run `git status`, `git branch`, etc in background to update the contents of panels). This does not run `git fetch`. |
2525
| `` + `` | 다음 스크린 모드 (normal/half/fullscreen) | |
2626
| `` _ `` | 이전 스크린 모드 | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | 취소 | |
2829
| `` ? `` | 매뉴 열기 | |
2930
| `` <c-s> `` | View filter-by-path options | View options for filtering the commit log, so that only commits matching the filter are shown. |

docs/keybindings/Keybindings_nl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2424
| `` R `` | Verversen | Refresh the git state (i.e. run `git status`, `git branch`, etc in background to update the contents of panels). This does not run `git fetch`. |
2525
| `` + `` | Volgende scherm modus (normaal/half/groot) | |
2626
| `` _ `` | Vorige scherm modus | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | Annuleren | |
2829
| `` ? `` | Open menu | |
2930
| `` <c-s> `` | Bekijk scoping opties | View options for filtering the commit log, so that only commits matching the filter are shown. |

docs/keybindings/Keybindings_pl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
2424
| `` R `` | Odśwież | Odśwież stan git (tj. uruchom `git status`, `git branch`, itp. w tle, aby zaktualizować zawartość paneli). To nie uruchamia `git fetch`. |
2525
| `` + `` | Następny tryb ekranu (normalny/półpełny/pełnoekranowy) | |
2626
| `` _ `` | Poprzedni tryb ekranu | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | Anuluj | |
2829
| `` ? `` | Otwórz menu przypisań klawiszy | |
2930
| `` <c-s> `` | Pokaż opcje filtrowania | Pokaż opcje filtrowania dziennika commitów, tak aby pokazywane były tylko commity pasujące do filtra. |

docs/keybindings/Keybindings_pt.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
2424
| `` R `` | Atualizar | Atualize o estado do git (ou seja, execute `git status`, `git branch`, etc em segundo plano para atualizar o conteúdo de painéis). Isso não executa `git fetch`. |
2525
| `` + `` | Next screen mode (normal/half/fullscreen) | |
2626
| `` _ `` | Prev screen mode | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | Cancelar | |
2829
| `` ? `` | Open keybindings menu | |
2930
| `` <c-s> `` | View filter options | View options for filtering the commit log, so that only commits matching the filter are shown. |

docs/keybindings/Keybindings_ru.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _Связки клавиш_
2424
| `` R `` | Обновить | Refresh the git state (i.e. run `git status`, `git branch`, etc in background to update the contents of panels). This does not run `git fetch`. |
2525
| `` + `` | Следующий режим экрана (нормальный/полуэкранный/полноэкранный) | |
2626
| `` _ `` | Предыдущий режим экрана | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | Отменить | |
2829
| `` ? `` | Открыть меню | |
2930
| `` <c-s> `` | Просмотреть параметры фильтрации по пути | View options for filtering the commit log, so that only commits matching the filter are shown. |

docs/keybindings/Keybindings_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
2424
| `` R `` | 刷新 | 刷新git状态(即在后台上运行`git status`,`git branch`等命令以更新面板内容) 不会运行`git fetch` |
2525
| `` + `` | 下一屏模式(正常/半屏/全屏) | |
2626
| `` _ `` | 上一屏模式 | |
27+
| `` | `` | Cycle pagers | Choose the next pager in the list of configured pagers |
2728
| `` <esc> `` | 取消 | |
2829
| `` ? `` | 打开菜单 | |
2930
| `` <c-s> `` | 查看按路径过滤选项 | 查看用于过滤提交日志的选项,以便仅显示与过滤器匹配的提交。 |

0 commit comments

Comments
 (0)