Skip to content

Commit 0bbf3d9

Browse files
committed
Add config options for length of commit hash displayed in commits view
- Add config option `commitHashLength` to to pkg/config/user_config.go - Add config option `commitStatusChar` to display a char if there is nothing else to show the status color. - Changed the hash display in pkg/gui/presentation/commits.go - Refactor `pkg/gui/presentation/commits.go` slightly to be consistent Change `func displayCommit()` so all the individual strings are built first, then the whole thing `cols` is put together. Before, most strings were built prior to constructing `cols`, but a few were built inside the `cols` construction.
1 parent aa81e19 commit 0bbf3d9

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

docs/Config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ 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
84+
commitStatusChar: "" # What to show instead of hash if commitHashLength==0 and NF icons aren't on. Empty string to show nothing.
8385
commandLogSize: 8
8486
splitDiff: 'auto' # one of 'auto' | 'always'
8587
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor

pkg/config/user_config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ 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.
127+
// If 0 and NF icons aren't enabled, show 'commitStatusChar' instead of hash.
128+
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
129+
// What to show instead of hash if commitHashLength==0 and NF icons aren't on
130+
// Empty string to show nothing
131+
CommitStatusChar string `yaml:"commitStatusChar"`
126132
// If true, show commit hashes alongside branch names in the branches view.
127133
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
128134
// Height of the command log view
@@ -675,6 +681,8 @@ func GetDefaultConfig() *UserConfig {
675681
ShowIcons: false,
676682
NerdFontsVersion: "",
677683
ShowFileIcons: true,
684+
CommitHashLength: 8,
685+
CommitStatusChar: "●",
678686
ShowBranchCommitHash: false,
679687
CommandLogSize: 8,
680688
SplitDiff: "auto",

pkg/gui/presentation/commits.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,32 @@ 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 := commit.Hash
318+
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
319+
hashLength := common.UserConfig.Gui.CommitHashLength
320+
if hashLength == 0 && !icons.IsIconEnabled() { // if no icons and no hash, show a char so user still sees status color
321+
hashString = common.UserConfig.Gui.CommitStatusChar
322+
} else if hashLength < len(hashString) {
323+
hashString = hashString[:hashLength]
324+
}
325+
hashString = hashColor.Sprint(hashString)
326+
327+
divergenceString := ""
328+
if commit.Divergence != models.DivergenceNone {
329+
divergenceString = hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓"))
330+
} else if icons.IsIconEnabled() {
331+
divergenceString = hashColor.Sprint(icons.IconForCommit(commit))
332+
}
333+
334+
descriptionString := ""
335+
if fullDescription {
336+
descriptionString = style.FgBlue.Sprint(
337+
utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat),
338+
)
339+
}
340+
318341
actionString := ""
319342
if commit.Action != models.ActionNone {
320343
todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String())
@@ -368,20 +391,12 @@ func displayCommit(
368391
}
369392

370393
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-
}
383394
cols = append(
384395
cols,
396+
divergenceString,
397+
hashString,
398+
bisectString,
399+
descriptionString,
385400
actionString,
386401
authorFunc(commit.AuthorName),
387402
graphLine+mark+tagString+theme.DefaultTextColor.Sprint(name),

schema/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@
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.\nIf 0 and NF icons aren't enabled, show 'commitStatusChar' instead of hash.",
316+
"default": 8
317+
},
318+
"commitStatusChar": {
319+
"type": "string",
320+
"description": "What to show instead of hash if commitHashLength==0 and NF icons aren't on\nEmpty string to show nothing",
321+
"default": ""
322+
},
312323
"showBranchCommitHash": {
313324
"type": "boolean",
314325
"description": "If true, show commit hashes alongside branch names in the branches view."

0 commit comments

Comments
 (0)