Skip to content

Commit 3af545d

Browse files
authored
Add user config gui.commitAuthorFormat (#3625)
- **PR Description** Adds configuration option defining whether to show full author names or their shortened form in the commit graph. Closes [#3624](#3624). - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 629b7ba + 57f9493 commit 3af545d

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

docs/Config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ gui:
181181
# If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
182182
showFileIcons: true
183183

184+
# Whether to show full author names or their shortened form in the commit graph.
185+
# One of 'auto' (default) | 'full' | 'short'
186+
# If 'auto', initials will be shown in small windows, and full names - in larger ones.
187+
commitAuthorFormat: auto
188+
184189
# Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
185190
commitHashLength: 8
186191

pkg/config/user_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ type GuiConfig struct {
125125
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
126126
// If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
127127
ShowFileIcons bool `yaml:"showFileIcons"`
128+
// Whether to show full author names or their shortened form in the commit graph.
129+
// One of 'auto' (default) | 'full' | 'short'
130+
// If 'auto', initials will be shown in small windows, and full names - in larger ones.
131+
CommitAuthorFormat string `yaml:"commitAuthorFormat" jsonschema:"enum=auto,enum=short,enum=full"`
128132
// Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
129133
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
130134
// If true, show commit hashes alongside branch names in the branches view.
@@ -676,6 +680,7 @@ func GetDefaultConfig() *UserConfig {
676680
UnstagedChangesColor: []string{"red"},
677681
DefaultFgColor: []string{"default"},
678682
},
683+
CommitAuthorFormat: "auto",
679684
CommitLength: CommitLengthConfig{Show: true},
680685
SkipNoStagedFilesWarning: false,
681686
ShowListFooter: true,

pkg/config/user_config_validation.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import (
77
)
88

99
func (config *UserConfig) Validate() error {
10+
if err := validateEnum("gui.commitAuthorFormat", config.Gui.CommitAuthorFormat,
11+
[]string{"auto", "short", "full"}); err != nil {
12+
return err
13+
}
14+
1015
if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView,
1116
[]string{"dashboard", "allBranchesLog"}); err != nil {
1217
return err

pkg/gui/presentation/commits.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,14 @@ func displayCommit(
440440
mark = fmt.Sprintf("%s ", willBeRebased)
441441
}
442442

443-
authorFunc := authors.ShortAuthor
444-
if fullDescription {
443+
var authorFunc func(string) string
444+
switch common.UserConfig.Gui.CommitAuthorFormat {
445+
case "short":
446+
authorFunc = authors.ShortAuthor
447+
case "full":
445448
authorFunc = authors.LongAuthor
449+
default:
450+
authorFunc = lo.Ternary(fullDescription, authors.LongAuthor, authors.ShortAuthor)
446451
}
447452

448453
cols := make([]string, 0, 7)

schema/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@
320320
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
321321
"default": true
322322
},
323+
"commitAuthorFormat": {
324+
"type": "string",
325+
"enum": [
326+
"auto",
327+
"short",
328+
"full"
329+
],
330+
"description": "Whether to show full author names or their shortened form in the commit graph.\nOne of 'auto' (default) | 'full' | 'short'\nIf 'auto', initials will be shown in small windows, and full names - in larger ones.",
331+
"default": "auto"
332+
},
323333
"commitHashLength": {
324334
"type": "integer",
325335
"minimum": 0,

0 commit comments

Comments
 (0)