diff --git a/docs/Config.md b/docs/Config.md index 4bd589fe095..2a59c8b974f 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -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 diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index c30d030aeaf..50ebac30f1f 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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 { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index c9252e03d60..ff3075fb39f 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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 { diff --git a/pkg/gui/presentation/icons/patch.go b/pkg/gui/presentation/icons/patch.go new file mode 100644 index 00000000000..2181bde83ff --- /dev/null +++ b/pkg/gui/presentation/icons/patch.go @@ -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) + } + } +} diff --git a/schema/config.json b/schema/config.json index aa4e41012c6..f7f347875da 100644 --- a/schema/config.json +++ b/schema/config.json @@ -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,