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](https://github.com/jesseduffield/lazygit/issues/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
This commit is contained in:
Stefan Haller 2024-06-15 16:17:48 +02:00 committed by GitHub
commit 3af545daf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 2 deletions

View file

@ -181,6 +181,11 @@ gui:
# If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
showFileIcons: true
# Whether to show full author names or their shortened form in the commit graph.
# One of 'auto' (default) | 'full' | 'short'
# If 'auto', initials will be shown in small windows, and full names - in larger ones.
commitAuthorFormat: auto
# Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
commitHashLength: 8

View file

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

View file

@ -7,6 +7,11 @@ import (
)
func (config *UserConfig) Validate() error {
if err := validateEnum("gui.commitAuthorFormat", config.Gui.CommitAuthorFormat,
[]string{"auto", "short", "full"}); err != nil {
return err
}
if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView,
[]string{"dashboard", "allBranchesLog"}); err != nil {
return err

View file

@ -440,9 +440,14 @@ func displayCommit(
mark = fmt.Sprintf("%s ", willBeRebased)
}
authorFunc := authors.ShortAuthor
if fullDescription {
var authorFunc func(string) string
switch common.UserConfig.Gui.CommitAuthorFormat {
case "short":
authorFunc = authors.ShortAuthor
case "full":
authorFunc = authors.LongAuthor
default:
authorFunc = lo.Ternary(fullDescription, authors.LongAuthor, authors.ShortAuthor)
}
cols := make([]string, 0, 7)

View file

@ -320,6 +320,16 @@
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
"default": true
},
"commitAuthorFormat": {
"type": "string",
"enum": [
"auto",
"short",
"full"
],
"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.",
"default": "auto"
},
"commitHashLength": {
"type": "integer",
"minimum": 0,