mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-16 09:27:37 +03:00
Replace paging config with an array of pagers
This commit is contained in:
@@ -319,26 +319,30 @@ gui:
|
|||||||
|
|
||||||
# Config relating to git
|
# Config relating to git
|
||||||
git:
|
git:
|
||||||
|
# Array of pagers. Each entry has the following format:
|
||||||
|
#
|
||||||
|
# # Value of the --color arg in the git diff command. Some pagers want
|
||||||
|
# # this to be set to 'always' and some want it set to 'never'
|
||||||
|
# colorArg: "always"
|
||||||
|
#
|
||||||
|
# # e.g.
|
||||||
|
# # diff-so-fancy
|
||||||
|
# # delta --dark --paging=never
|
||||||
|
# # ydiff -p cat -s --wrap --width={{columnWidth}}
|
||||||
|
# pager: ""
|
||||||
|
#
|
||||||
|
# # e.g. 'difft --color=always'
|
||||||
|
# externalDiffCommand: ""
|
||||||
|
#
|
||||||
|
# # If true, Lazygit will use git's `diff.external` config for paging.
|
||||||
|
# # The advantage over `externalDiffCommand` is that this can be
|
||||||
|
# # configured per file type in .gitattributes; see
|
||||||
|
# # https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
|
||||||
|
# useExternalDiffGitConfig: false
|
||||||
|
#
|
||||||
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md
|
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md
|
||||||
paging:
|
# for more information.
|
||||||
# Value of the --color arg in the git diff command. Some pagers want this to be
|
pagers: []
|
||||||
# set to 'always' and some want it set to 'never'
|
|
||||||
colorArg: always
|
|
||||||
|
|
||||||
# e.g.
|
|
||||||
# diff-so-fancy
|
|
||||||
# delta --dark --paging=never
|
|
||||||
# ydiff -p cat -s --wrap --width={{columnWidth}}
|
|
||||||
pager: ""
|
|
||||||
|
|
||||||
# e.g. 'difft --color=always'
|
|
||||||
externalDiffCommand: ""
|
|
||||||
|
|
||||||
# If true, Lazygit will use git's `diff.external` config for paging. The
|
|
||||||
# advantage over `externalDiffCommand` is that this can be configured per file
|
|
||||||
# type in .gitattributes; see
|
|
||||||
# https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
|
|
||||||
useExternalDiffGitConfig: false
|
|
||||||
|
|
||||||
# Config relating to committing
|
# Config relating to committing
|
||||||
commit:
|
commit:
|
||||||
@@ -638,6 +642,7 @@ keybinding:
|
|||||||
prevTab: '['
|
prevTab: '['
|
||||||
nextScreenMode: +
|
nextScreenMode: +
|
||||||
prevScreenMode: _
|
prevScreenMode: _
|
||||||
|
cyclePagers: '|'
|
||||||
undo: z
|
undo: z
|
||||||
redo: Z
|
redo: Z
|
||||||
filteringMenu: <c-s>
|
filteringMenu: <c-s>
|
||||||
|
@@ -4,23 +4,27 @@ Lazygit supports custom pagers, [configured](/docs/Config.md) in the config.yml
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
## Default:
|
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.
|
||||||
|
|
||||||
|
Pagers are configured with the `pagers` array in the git section; here's an example for a multi-pager setup:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
colorArg: always
|
- pager: delta --dark --paging=never
|
||||||
|
- pager: ydiff -p cat -s --wrap --width={{columnWidth}}
|
||||||
|
colorArg: never
|
||||||
|
- externalDiffCommand: difft --color=always
|
||||||
```
|
```
|
||||||
|
|
||||||
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 `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.
|
||||||
|
|
||||||
## Delta:
|
## Delta:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
colorArg: always
|
- pager: delta --dark --paging=never
|
||||||
pager: delta --dark --paging=never
|
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
@@ -31,9 +35,8 @@ A cool feature of delta is --hyperlinks, which renders clickable links for the l
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
colorArg: always
|
- pager: diff-so-fancy
|
||||||
pager: diff-so-fancy
|
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
@@ -44,9 +47,9 @@ git:
|
|||||||
gui:
|
gui:
|
||||||
sidePanelWidth: 0.2 # gives you more space to show things side-by-side
|
sidePanelWidth: 0.2 # gives you more space to show things side-by-side
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
colorArg: never
|
- colorArg: never
|
||||||
pager: ydiff -p cat -s --wrap --width={{columnWidth}}
|
pager: ydiff -p cat -s --wrap --width={{columnWidth}}
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
@@ -61,8 +64,8 @@ These can be used in lazygit by using the `externalDiffCommand` config; in the c
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
externalDiffCommand: difft --color=always
|
- externalDiffCommand: difft --color=always
|
||||||
```
|
```
|
||||||
|
|
||||||
The `colorArg` and `pager` options are not used in this case.
|
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
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
externalDiffCommand: difft --color=always --display=inline --syntax-highlight=off
|
- externalDiffCommand: difft --color=always --display=inline --syntax-highlight=off
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
useExternalDiffGitConfig: true
|
- useExternalDiffGitConfig: true
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
git:
|
git:
|
||||||
paging:
|
pagers:
|
||||||
externalDiffCommand: "C:/wherever/lazygit-pager.ps1"
|
- externalDiffCommand: "C:/wherever/lazygit-pager.ps1"
|
||||||
```
|
```
|
||||||
|
|
||||||
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.)
|
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.)
|
||||||
|
@@ -255,8 +255,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize uint64
|
contextSize uint64
|
||||||
similarityThreshold int
|
similarityThreshold int
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
extDiffCmd string
|
pagerConfig *config.PagingConfig
|
||||||
useExtDiffGitConfig bool
|
|
||||||
expected []string
|
expected []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +266,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "",
|
pagerConfig: nil,
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -276,7 +275,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "",
|
pagerConfig: nil,
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--", "file.txt"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--", "file.txt"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -285,7 +284,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 77,
|
contextSize: 77,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "",
|
pagerConfig: nil,
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -294,7 +293,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 33,
|
similarityThreshold: 33,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "",
|
pagerConfig: nil,
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=33%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=33%", "--"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -303,7 +302,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 77,
|
contextSize: 77,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: true,
|
ignoreWhitespace: true,
|
||||||
extDiffCmd: "",
|
pagerConfig: nil,
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space", "--find-renames=50%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space", "--find-renames=50%", "--"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -312,7 +311,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "difft --color=always",
|
pagerConfig: &config.PagingConfig{ExternalDiffCommand: "difft --color=always"},
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -321,7 +320,7 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
useExtDiffGitConfig: true,
|
pagerConfig: &config.PagingConfig{UseExternalDiffGitConfig: true},
|
||||||
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -329,11 +328,12 @@ func TestCommitShowCmdObj(t *testing.T) {
|
|||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
userConfig := config.GetDefaultConfig()
|
userConfig := config.GetDefaultConfig()
|
||||||
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
|
if s.pagerConfig != nil {
|
||||||
|
userConfig.Git.Pagers = []config.PagingConfig{*s.pagerConfig}
|
||||||
|
}
|
||||||
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
|
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
|
||||||
userConfig.Git.Paging.UseExternalDiffGitConfig = s.useExtDiffGitConfig
|
|
||||||
|
|
||||||
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
|
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
|
||||||
repoPaths := RepoPaths{
|
repoPaths := RepoPaths{
|
||||||
|
@@ -103,8 +103,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize uint64
|
contextSize uint64
|
||||||
similarityThreshold int
|
similarityThreshold int
|
||||||
ignoreWhitespace bool
|
ignoreWhitespace bool
|
||||||
extDiffCmd string
|
pagerConfig *config.PagingConfig
|
||||||
useExtDiffGitConfig bool
|
|
||||||
expected []string
|
expected []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +138,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
extDiffCmd: "difft --color=always",
|
pagerConfig: &config.PagingConfig{ExternalDiffCommand: "difft --color=always"},
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "stash", "show", "-p", "--stat", "-u", "--ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "stash", "show", "-p", "--stat", "-u", "--ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -148,7 +147,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
useExtDiffGitConfig: true,
|
pagerConfig: &config.PagingConfig{UseExternalDiffGitConfig: true},
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -167,8 +166,9 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
|
||||||
userConfig.Git.DiffContextSize = s.contextSize
|
userConfig.Git.DiffContextSize = s.contextSize
|
||||||
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
|
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
|
||||||
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
|
if s.pagerConfig != nil {
|
||||||
userConfig.Git.Paging.UseExternalDiffGitConfig = s.useExtDiffGitConfig
|
userConfig.Git.Pagers = []config.PagingConfig{*s.pagerConfig}
|
||||||
|
}
|
||||||
repoPaths := RepoPaths{
|
repoPaths := RepoPaths{
|
||||||
worktreePath: "/path/to/worktree",
|
worktreePath: "/path/to/worktree",
|
||||||
}
|
}
|
||||||
|
@@ -8,29 +8,75 @@ import (
|
|||||||
|
|
||||||
type PagerConfig struct {
|
type PagerConfig struct {
|
||||||
getUserConfig func() *UserConfig
|
getUserConfig func() *UserConfig
|
||||||
|
pagerIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPagerConfig(getUserConfig func() *UserConfig) *PagerConfig {
|
func NewPagerConfig(getUserConfig func() *UserConfig) *PagerConfig {
|
||||||
return &PagerConfig{getUserConfig: getUserConfig}
|
return &PagerConfig{getUserConfig: getUserConfig}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *PagerConfig) currentPagerConfig() *PagingConfig {
|
||||||
|
pagers := self.getUserConfig().Git.Pagers
|
||||||
|
if len(pagers) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guard against the pager index being out of range, which can happen if the user
|
||||||
|
// has removed pagers from their config file while lazygit is running.
|
||||||
|
if self.pagerIndex >= len(pagers) {
|
||||||
|
self.pagerIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pagers[self.pagerIndex]
|
||||||
|
}
|
||||||
|
|
||||||
func (self *PagerConfig) GetPagerCommand(width int) string {
|
func (self *PagerConfig) GetPagerCommand(width int) string {
|
||||||
|
currentPagerConfig := self.currentPagerConfig()
|
||||||
|
if currentPagerConfig == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
templateValues := map[string]string{
|
templateValues := map[string]string{
|
||||||
"columnWidth": strconv.Itoa(width/2 - 6),
|
"columnWidth": strconv.Itoa(width/2 - 6),
|
||||||
}
|
}
|
||||||
|
|
||||||
pagerTemplate := string(self.getUserConfig().Git.Paging.Pager)
|
pagerTemplate := string(currentPagerConfig.Pager)
|
||||||
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PagerConfig) GetColorArg() string {
|
func (self *PagerConfig) GetColorArg() string {
|
||||||
return self.getUserConfig().Git.Paging.ColorArg
|
currentPagerConfig := self.currentPagerConfig()
|
||||||
|
if currentPagerConfig == nil {
|
||||||
|
return "always"
|
||||||
|
}
|
||||||
|
|
||||||
|
colorArg := currentPagerConfig.ColorArg
|
||||||
|
if colorArg == "" {
|
||||||
|
return "always"
|
||||||
|
}
|
||||||
|
return colorArg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PagerConfig) GetExternalDiffCommand() string {
|
func (self *PagerConfig) GetExternalDiffCommand() string {
|
||||||
return self.getUserConfig().Git.Paging.ExternalDiffCommand
|
currentPagerConfig := self.currentPagerConfig()
|
||||||
|
if currentPagerConfig == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return currentPagerConfig.ExternalDiffCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PagerConfig) GetUseExternalDiffGitConfig() bool {
|
func (self *PagerConfig) GetUseExternalDiffGitConfig() bool {
|
||||||
return self.getUserConfig().Git.Paging.UseExternalDiffGitConfig
|
currentPagerConfig := self.currentPagerConfig()
|
||||||
|
if currentPagerConfig == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return currentPagerConfig.UseExternalDiffGitConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *PagerConfig) CyclePagers() {
|
||||||
|
self.pagerIndex = (self.pagerIndex + 1) % len(self.getUserConfig().Git.Pagers)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *PagerConfig) CurrentPagerIndex() (int, int) {
|
||||||
|
return self.pagerIndex, len(self.getUserConfig().Git.Pagers)
|
||||||
}
|
}
|
||||||
|
@@ -233,8 +233,30 @@ type SpinnerConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GitConfig struct {
|
type GitConfig struct {
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md
|
// Array of pagers. Each entry has the following format:
|
||||||
Paging PagingConfig `yaml:"paging"`
|
// [dev] The following documentation is duplicated from the PagingConfig struct below.
|
||||||
|
//
|
||||||
|
// # Value of the --color arg in the git diff command. Some pagers want
|
||||||
|
// # this to be set to 'always' and some want it set to 'never'
|
||||||
|
// colorArg: "always"
|
||||||
|
//
|
||||||
|
// # e.g.
|
||||||
|
// # diff-so-fancy
|
||||||
|
// # delta --dark --paging=never
|
||||||
|
// # ydiff -p cat -s --wrap --width={{columnWidth}}
|
||||||
|
// pager: ""
|
||||||
|
//
|
||||||
|
// # e.g. 'difft --color=always'
|
||||||
|
// externalDiffCommand: ""
|
||||||
|
//
|
||||||
|
// # If true, Lazygit will use git's `diff.external` config for paging.
|
||||||
|
// # The advantage over `externalDiffCommand` is that this can be
|
||||||
|
// # configured per file type in .gitattributes; see
|
||||||
|
// # https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.
|
||||||
|
// useExternalDiffGitConfig: false
|
||||||
|
//
|
||||||
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md for more information.
|
||||||
|
Pagers []PagingConfig `yaml:"pagers"`
|
||||||
// Config relating to committing
|
// Config relating to committing
|
||||||
Commit CommitConfig `yaml:"commit"`
|
Commit CommitConfig `yaml:"commit"`
|
||||||
// Config relating to merging
|
// Config relating to merging
|
||||||
@@ -301,6 +323,7 @@ func (PagerType) JSONSchemaExtend(schema *jsonschema.Schema) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [dev] This documentation is duplicated in the GitConfig struct. If you make changes here, make them there too.
|
||||||
type PagingConfig struct {
|
type PagingConfig struct {
|
||||||
// Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'
|
// Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'
|
||||||
ColorArg string `yaml:"colorArg" jsonschema:"enum=always,enum=never"`
|
ColorArg string `yaml:"colorArg" jsonschema:"enum=always,enum=never"`
|
||||||
@@ -441,6 +464,7 @@ type KeybindingUniversalConfig struct {
|
|||||||
PrevTab string `yaml:"prevTab"`
|
PrevTab string `yaml:"prevTab"`
|
||||||
NextScreenMode string `yaml:"nextScreenMode"`
|
NextScreenMode string `yaml:"nextScreenMode"`
|
||||||
PrevScreenMode string `yaml:"prevScreenMode"`
|
PrevScreenMode string `yaml:"prevScreenMode"`
|
||||||
|
CyclePagers string `yaml:"cyclePagers"`
|
||||||
Undo string `yaml:"undo"`
|
Undo string `yaml:"undo"`
|
||||||
Redo string `yaml:"redo"`
|
Redo string `yaml:"redo"`
|
||||||
FilteringMenu string `yaml:"filteringMenu"`
|
FilteringMenu string `yaml:"filteringMenu"`
|
||||||
@@ -784,11 +808,6 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
SwitchTabsWithPanelJumpKeys: false,
|
SwitchTabsWithPanelJumpKeys: false,
|
||||||
},
|
},
|
||||||
Git: GitConfig{
|
Git: GitConfig{
|
||||||
Paging: PagingConfig{
|
|
||||||
ColorArg: "always",
|
|
||||||
Pager: "",
|
|
||||||
ExternalDiffCommand: "",
|
|
||||||
},
|
|
||||||
Commit: CommitConfig{
|
Commit: CommitConfig{
|
||||||
SignOff: false,
|
SignOff: false,
|
||||||
AutoWrapCommitMessage: true,
|
AutoWrapCommitMessage: true,
|
||||||
@@ -904,6 +923,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
PrevTab: "[",
|
PrevTab: "[",
|
||||||
NextScreenMode: "+",
|
NextScreenMode: "+",
|
||||||
PrevScreenMode: "_",
|
PrevScreenMode: "_",
|
||||||
|
CyclePagers: "|",
|
||||||
Undo: "z",
|
Undo: "z",
|
||||||
Redo: "Z",
|
Redo: "Z",
|
||||||
FilteringMenu: "<c-s>",
|
FilteringMenu: "<c-s>",
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@@ -58,6 +60,13 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
|
|||||||
Handler: opts.Guards.NoPopupPanel(self.prevScreenMode),
|
Handler: opts.Guards.NoPopupPanel(self.prevScreenMode),
|
||||||
Description: self.c.Tr.PrevScreenMode,
|
Description: self.c.Tr.PrevScreenMode,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Universal.CyclePagers),
|
||||||
|
Handler: opts.Guards.NoPopupPanel(self.cyclePagers),
|
||||||
|
GetDisabledReason: self.canCyclePagers,
|
||||||
|
Description: self.c.Tr.CyclePagers,
|
||||||
|
Tooltip: self.c.Tr.CyclePagersTooltip,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Key: opts.GetKey(opts.Config.Universal.Return),
|
Key: opts.GetKey(opts.Config.Universal.Return),
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
@@ -171,6 +180,27 @@ func (self *GlobalController) prevScreenMode() error {
|
|||||||
return (&ScreenModeActions{c: self.c}).Prev()
|
return (&ScreenModeActions{c: self.c}).Prev()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *GlobalController) cyclePagers() error {
|
||||||
|
self.c.State().GetPagerConfig().CyclePagers()
|
||||||
|
if self.c.Context().CurrentSide().GetKey() == self.c.Context().Current().GetKey() {
|
||||||
|
self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
|
||||||
|
}
|
||||||
|
|
||||||
|
current, total := self.c.State().GetPagerConfig().CurrentPagerIndex()
|
||||||
|
self.c.Toast(fmt.Sprintf("Selected pager %d of %d", current+1, total))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *GlobalController) canCyclePagers() *types.DisabledReason {
|
||||||
|
_, total := self.c.State().GetPagerConfig().CurrentPagerIndex()
|
||||||
|
if total <= 1 {
|
||||||
|
return &types.DisabledReason{
|
||||||
|
Text: self.c.Tr.CyclePagersDisabledReason,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *GlobalController) createOptionsMenu() error {
|
func (self *GlobalController) createOptionsMenu() error {
|
||||||
return (&OptionsMenuAction{c: self.c}).Call()
|
return (&OptionsMenuAction{c: self.c}).Call()
|
||||||
}
|
}
|
||||||
|
@@ -585,6 +585,9 @@ type TranslationSet struct {
|
|||||||
ViewResetToUpstreamOptions string
|
ViewResetToUpstreamOptions string
|
||||||
NextScreenMode string
|
NextScreenMode string
|
||||||
PrevScreenMode string
|
PrevScreenMode string
|
||||||
|
CyclePagers string
|
||||||
|
CyclePagersTooltip string
|
||||||
|
CyclePagersDisabledReason string
|
||||||
StartSearch string
|
StartSearch string
|
||||||
StartFilter string
|
StartFilter string
|
||||||
Keybindings string
|
Keybindings string
|
||||||
@@ -1678,6 +1681,9 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
ViewResetToUpstreamOptions: "View upstream reset options",
|
ViewResetToUpstreamOptions: "View upstream reset options",
|
||||||
NextScreenMode: "Next screen mode (normal/half/fullscreen)",
|
NextScreenMode: "Next screen mode (normal/half/fullscreen)",
|
||||||
PrevScreenMode: "Prev screen mode",
|
PrevScreenMode: "Prev screen mode",
|
||||||
|
CyclePagers: "Cycle pagers",
|
||||||
|
CyclePagersTooltip: "Choose the next pager in the list of configured pagers",
|
||||||
|
CyclePagersDisabledReason: "No other pagers configured",
|
||||||
StartSearch: "Search the current view by text",
|
StartSearch: "Search the current view by text",
|
||||||
StartFilter: "Filter the current view by text",
|
StartFilter: "Filter the current view by text",
|
||||||
KeybindingsLegend: "Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b",
|
KeybindingsLegend: "Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b",
|
||||||
|
@@ -285,9 +285,12 @@
|
|||||||
},
|
},
|
||||||
"GitConfig": {
|
"GitConfig": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"paging": {
|
"pagers": {
|
||||||
"$ref": "#/$defs/PagingConfig",
|
"items": {
|
||||||
"description": "See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md"
|
"$ref": "#/$defs/PagingConfig"
|
||||||
|
},
|
||||||
|
"type": "array",
|
||||||
|
"description": "Array of pagers. Each entry has the following format:\n\n # Value of the --color arg in the git diff command. Some pagers want\n # this to be set to 'always' and some want it set to 'never'\n colorArg: \"always\"\n\n # e.g.\n # diff-so-fancy\n # delta --dark --paging=never\n # ydiff -p cat -s --wrap --width={{columnWidth}}\n pager: \"\"\n\n # e.g. 'difft --color=always'\n externalDiffCommand: \"\"\n\n # If true, Lazygit will use git's `diff.external` config for paging.\n # The advantage over `externalDiffCommand` is that this can be\n # configured per file type in .gitattributes; see\n # https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.\n useExternalDiffGitConfig: false\n\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md for more information."
|
||||||
},
|
},
|
||||||
"commit": {
|
"commit": {
|
||||||
"$ref": "#/$defs/CommitConfig",
|
"$ref": "#/$defs/CommitConfig",
|
||||||
@@ -1464,6 +1467,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "_"
|
"default": "_"
|
||||||
},
|
},
|
||||||
|
"cyclePagers": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "|"
|
||||||
|
},
|
||||||
"undo": {
|
"undo": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "z"
|
"default": "z"
|
||||||
@@ -1667,13 +1674,11 @@
|
|||||||
"always",
|
"always",
|
||||||
"never"
|
"never"
|
||||||
],
|
],
|
||||||
"description": "Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'",
|
"description": "Value of the --color arg in the git diff command. Some pagers want this to be set to 'always' and some want it set to 'never'"
|
||||||
"default": "always"
|
|
||||||
},
|
},
|
||||||
"pager": {
|
"pager": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "e.g.\ndiff-so-fancy\ndelta --dark --paging=never\nydiff -p cat -s --wrap --width={{columnWidth}}",
|
"description": "e.g.\ndiff-so-fancy\ndelta --dark --paging=never\nydiff -p cat -s --wrap --width={{columnWidth}}",
|
||||||
"default": "",
|
|
||||||
"examples": [
|
"examples": [
|
||||||
"delta --dark --paging=never",
|
"delta --dark --paging=never",
|
||||||
"diff-so-fancy",
|
"diff-so-fancy",
|
||||||
@@ -1686,13 +1691,11 @@
|
|||||||
},
|
},
|
||||||
"useExternalDiffGitConfig": {
|
"useExternalDiffGitConfig": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "If true, Lazygit will use git's `diff.external` config for paging. The advantage over `externalDiffCommand` is that this can be configured per file type in .gitattributes; see https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver.",
|
"description": "If true, Lazygit will use git's `diff.external` config for paging. The advantage over `externalDiffCommand` is that this can be configured per file type in .gitattributes; see https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver."
|
||||||
"default": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"type": "object",
|
"type": "object"
|
||||||
"description": "See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md"
|
|
||||||
},
|
},
|
||||||
"RefresherConfig": {
|
"RefresherConfig": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
Reference in New Issue
Block a user