Skip to content

Commit b3a60ce

Browse files
authored
Add config options for length of commit hash displayed in commits view (#3505)
- **PR Description** Add a new config option `gui.commitHashLength` to change the length of the commit hash displayed in commits view. default: <img width="472" alt="image" src="https://github.com/jesseduffield/lazygit/assets/98684296/36dced1e-0c74-4dbd-8670-98e17a75d83a"> With config: ```yaml gui: commitHashLength: 3 ``` <img width="463" alt="image" src="https://github.com/jesseduffield/lazygit/assets/98684296/e8023cd8-f138-4af8-ae0e-3661f80206ca"> - Changes - Added the user config option to to `pkg/config/user_config.go` and `schema/config.json` - documented in `docs/Config.md` - Changed the code that displays the hash in `pkg/gui/presentation/commits.go` --- - **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 (specifically `docs/Config.md`) have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents aa81e19 + b63321a commit b3a60ce

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

docs/Config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ gui:
8080
showIcons: false # deprecated: use nerdFontsVersion instead
8181
nerdFontsVersion: "" # nerd fonts version to use ("2" or "3"); empty means don't show nerd font icons
8282
showFileIcons: true # for hiding file icons in the file views
83+
commitHashLength: 8 # length of commit hash in commits view. 0 shows '*' if NF icons aren't enabled
8384
commandLogSize: 8
8485
splitDiff: 'auto' # one of 'auto' | 'always'
8586
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor

pkg/config/user_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ type GuiConfig struct {
123123
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
124124
// If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
125125
ShowFileIcons bool `yaml:"showFileIcons"`
126+
// Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
127+
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
126128
// If true, show commit hashes alongside branch names in the branches view.
127129
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
128130
// Height of the command log view
@@ -675,6 +677,7 @@ func GetDefaultConfig() *UserConfig {
675677
ShowIcons: false,
676678
NerdFontsVersion: "",
677679
ShowFileIcons: true,
680+
CommitHashLength: 8,
678681
ShowBranchCommitHash: false,
679682
CommandLogSize: 8,
680683
SplitDiff: "auto",

pkg/gui/presentation/commits.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,33 @@ func displayCommit(
312312
bisectInfo *git_commands.BisectInfo,
313313
isYouAreHereCommit bool,
314314
) []string {
315-
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
316315
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
317316

317+
hashString := ""
318+
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
319+
hashLength := common.UserConfig.Gui.CommitHashLength
320+
if hashLength >= len(commit.Hash) {
321+
hashString = hashColor.Sprint(commit.Hash)
322+
} else if hashLength > 0 {
323+
hashString = hashColor.Sprint(commit.Hash[:hashLength])
324+
} else if !icons.IsIconEnabled() { // hashLength <= 0
325+
hashString = hashColor.Sprint("*")
326+
}
327+
328+
divergenceString := ""
329+
if commit.Divergence != models.DivergenceNone {
330+
divergenceString = hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓"))
331+
} else if icons.IsIconEnabled() {
332+
divergenceString = hashColor.Sprint(icons.IconForCommit(commit))
333+
}
334+
335+
descriptionString := ""
336+
if fullDescription {
337+
descriptionString = style.FgBlue.Sprint(
338+
utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat),
339+
)
340+
}
341+
318342
actionString := ""
319343
if commit.Action != models.ActionNone {
320344
todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String())
@@ -368,20 +392,12 @@ func displayCommit(
368392
}
369393

370394
cols := make([]string, 0, 7)
371-
if commit.Divergence != models.DivergenceNone {
372-
cols = append(cols, hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓")))
373-
} else if icons.IsIconEnabled() {
374-
cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit)))
375-
}
376-
cols = append(cols, hashColor.Sprint(commit.ShortHash()))
377-
cols = append(cols, bisectString)
378-
if fullDescription {
379-
cols = append(cols, style.FgBlue.Sprint(
380-
utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat),
381-
))
382-
}
383395
cols = append(
384396
cols,
397+
divergenceString,
398+
hashString,
399+
bisectString,
400+
descriptionString,
385401
actionString,
386402
authorFunc(commit.AuthorName),
387403
graphLine+mark+tagString+theme.DefaultTextColor.Sprint(name),

schema/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@
309309
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
310310
"default": true
311311
},
312+
"commitHashLength": {
313+
"type": "integer",
314+
"minimum": 0,
315+
"description": "Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.",
316+
"default": 8
317+
},
312318
"showBranchCommitHash": {
313319
"type": "boolean",
314320
"description": "If true, show commit hashes alongside branch names in the branches view."

0 commit comments

Comments
 (0)