Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ gui:
# Map of file extensions (including the dot) to icon properties (icon and color)
extensions: {}

# Map of vcs icons to string (icon only)
vcsIcons: {}

# Map of file icons to string (icon only)
fileIcons: {}

# The number of lines you scroll by when scrolling the main window
scrollHeight: 2

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ type CustomIconsConfig struct {
Filenames map[string]IconProperties `yaml:"filenames"`
// Map of file extensions (including the dot) to icon properties (icon and color)
Extensions map[string]IconProperties `yaml:"extensions"`
// Map of vcs icons to string (icon only)
VCSIcons map[string]string `yaml:"vcsIcons"`
// Map of file icons to string (icon only)
FileIcons map[string]IconProperties `yaml:"fileIcons"`
}

type IconProperties struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,12 @@ func (gui *Gui) onUserConfigLoaded() error {
authors.SetCustomAuthors(userConfig.Gui.AuthorColors)
if userConfig.Gui.NerdFontsVersion != "" {
icons.SetNerdFontsVersion(userConfig.Gui.NerdFontsVersion)

icons.PatchHardcodedIcons(userConfig.Gui.CustomIcons)
} else if userConfig.Gui.ShowIcons {
icons.SetNerdFontsVersion("2")

icons.PatchHardcodedIcons(userConfig.Gui.CustomIcons)
}

if len(userConfig.Gui.BranchColorPatterns) > 0 {
Expand Down
55 changes: 55 additions & 0 deletions pkg/gui/presentation/icons/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package icons

import "github.com/jesseduffield/lazygit/pkg/config"

func PatchHardcodedIcons(customIcons config.CustomIconsConfig) {
patchFileIconFromConfig(customIcons.FileIcons)
patchVCSIconFromConfig(customIcons.VCSIcons)
}

func patchVCSIconFromConfig(vcsIcons map[string]string) {
for name, icon := range vcsIcons {
// replace Variables(e.x: SOME_UPPER_SNAKECASE_VARIABLE)
switch name {
case "branch":
BRANCH_ICON = icon
case "detached-head":
DETACHED_HEAD_ICON = icon
case "tag":
TAG_ICON = icon
case "commit":
COMMIT_ICON = icon
case "merge-commit":
MERGE_COMMIT_ICON = icon
case "remote":
DEFAULT_REMOTE_ICON = icon
case "stash":
STASH_ICON = icon
case "linked-worktree":
LINKED_WORKTREE_ICON = icon
case "missing-linked-worktree":
MISSING_LINKED_WORKTREE_ICON = icon
}
// replace value in remoteIconsMap if the key exists.
if _, ok := remoteIcons[name]; ok {
remoteIcons[name] = icon
}
}
}

func changeStruct(p config.IconProperties) IconProperties {
return IconProperties{Icon: p.Icon, Color: p.Color}
}

func patchFileIconFromConfig(fileIcons map[string]config.IconProperties) {
for name, icon := range fileIcons {
switch name {
case "file":
DEFAULT_FILE_ICON = changeStruct(icon)
case "submodule":
DEFAULT_SUBMODULE_ICON = changeStruct(icon)
case "directory":
DEFAULT_DIRECTORY_ICON = changeStruct(icon)
}
}
}
14 changes: 14 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@
},
"type": "object",
"description": "Map of file extensions (including the dot) to icon properties (icon and color)"
},
"vcsIcons": {
"additionalProperties": {
"type": "string"
},
"type": "object",
"description": "Map of vcs icons to string (icon only)"
},
"fileIcons": {
"additionalProperties": {
"$ref": "#/$defs/IconProperties"
},
"type": "object",
"description": "Map of file icons to string (icon only)"
}
},
"additionalProperties": false,
Expand Down