1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-15 01:34:26 +02:00

Merge pull request #2731 from jesseduffield/config-for-nerd-fonts-version

Add config for nerd fonts version
This commit is contained in:
Stefan Haller
2023-06-22 18:55:05 +02:00
committed by GitHub
6 changed files with 317 additions and 278 deletions

View File

@ -62,7 +62,8 @@ gui:
experimentalShowBranchHeads: false # visualize branch heads with (*) in commits list experimentalShowBranchHeads: false # visualize branch heads with (*) in commits list
showBottomLine: true # for hiding the bottom information line (unless it has important information to tell you) showBottomLine: true # for hiding the bottom information line (unless it has important information to tell you)
showCommandLog: true showCommandLog: true
showIcons: false showIcons: false # deprecated: use nerdFontsVersion instead
nerdFontsVersion: "" # nerd fonts version to use ("2" or "3"); empty means don't show nerd font icons
commandLogSize: 8 commandLogSize: 8
splitDiff: 'auto' # one of 'auto' | 'always' splitDiff: 'auto' # one of 'auto' | 'always'
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor
@ -420,9 +421,12 @@ If you are using [Nerd Fonts](https://www.nerdfonts.com), you can display icons.
```yaml ```yaml
gui: gui:
showIcons: true nerdFontsVersion: "3"
``` ```
Supported versions are "2" and "3". The deprecated config `showIcons` sets the
version to "2" for backwards compatibility.
## Keybindings ## Keybindings
For all possible keybinding options, check [Custom_Keybindings.md](https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md) For all possible keybinding options, check [Custom_Keybindings.md](https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md)

View File

@ -49,6 +49,7 @@ type GuiConfig struct {
ShowCommandLog bool `yaml:"showCommandLog"` ShowCommandLog bool `yaml:"showCommandLog"`
ShowBottomLine bool `yaml:"showBottomLine"` ShowBottomLine bool `yaml:"showBottomLine"`
ShowIcons bool `yaml:"showIcons"` ShowIcons bool `yaml:"showIcons"`
NerdFontsVersion string `yaml:"nerdFontsVersion"`
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"` ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
ExperimentalShowBranchHeads bool `yaml:"experimentalShowBranchHeads"` ExperimentalShowBranchHeads bool `yaml:"experimentalShowBranchHeads"`
CommandLogSize int `yaml:"commandLogSize"` CommandLogSize int `yaml:"commandLogSize"`
@ -426,6 +427,7 @@ func GetDefaultConfig() *UserConfig {
ShowFileTree: true, ShowFileTree: true,
ShowRandomTip: true, ShowRandomTip: true,
ShowIcons: false, ShowIcons: false,
NerdFontsVersion: "",
ExperimentalShowBranchHeads: false, ExperimentalShowBranchHeads: false,
ShowBranchCommitHash: false, ShowBranchCommitHash: false,
CommandLogSize: 8, CommandLogSize: 8,

View File

@ -496,7 +496,11 @@ func NewGui(
gui.c = helperCommon gui.c = helperCommon
authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors) authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors)
icons.SetIconEnabled(gui.UserConfig.Gui.ShowIcons) if gui.UserConfig.Gui.NerdFontsVersion != "" {
icons.SetNerdFontsVersion(gui.UserConfig.Gui.NerdFontsVersion)
} else if gui.UserConfig.Gui.ShowIcons {
icons.SetNerdFontsVersion("2")
}
presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors) presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors)
gui.BackgroundRoutineMgr = &BackgroundRoutineMgr{gui: gui} gui.BackgroundRoutineMgr = &BackgroundRoutineMgr{gui: gui}

View File

@ -89,13 +89,13 @@ var extIconMap = map[string]string{
".cp": "\ue61d", //  ".cp": "\ue61d", // 
".cpio": "\uf410", //  ".cpio": "\uf410", // 
".cpp": "\ue61d", //  ".cpp": "\ue61d", // 
".cs": "\uf81a", // ".cs": "\U000f031b", // 󰌛
".csh": "\uf489", //  ".csh": "\uf489", // 
".cshtml": "\uf1fa", //  ".cshtml": "\uf1fa", // 
".csproj": "\uf81a", // ".csproj": "\U000f031b", // 󰌛
".css": "\ue749", //  ".css": "\ue749", // 
".csv": "\uf1c3", //  ".csv": "\uf1c3", // 
".csx": "\uf81a", // ".csx": "\U000f031b", // 󰌛
".cxx": "\ue61d", //  ".cxx": "\ue61d", // 
".d": "\ue7af", //  ".d": "\ue7af", // 
".dart": "\ue798", //  ".dart": "\ue798", // 
@ -184,7 +184,7 @@ var extIconMap = map[string]string{
".latex": "\uf034", //  ".latex": "\uf034", // 
".less": "\ue758", //  ".less": "\ue758", // 
".lhs": "\ue777", //  ".lhs": "\ue777", // 
".license": "\uf718", // ".license": "\U000f0219", // 󰈙
".localized": "\uf179", //  ".localized": "\uf179", // 
".lock": "\uf023", //  ".lock": "\uf023", // 
".log": "\uf18d", //  ".log": "\uf18d", // 
@ -210,7 +210,7 @@ var extIconMap = map[string]string{
".msi": "\ue70f", //  ".msi": "\ue70f", // 
".mustache": "\ue60f", //  ".mustache": "\ue60f", // 
".nix": "\uf313", //  ".nix": "\uf313", // 
".node": "\uf898", // ".node": "\U000f0399", // 󰎙
".npmignore": "\ue71e", //  ".npmignore": "\ue71e", // 
".odp": "\uf1c4", //  ".odp": "\uf1c4", // 
".ods": "\uf1c3", //  ".ods": "\uf1c3", // 
@ -251,7 +251,7 @@ var extIconMap = map[string]string{
".rspec_parallel": "\ue21e", //  ".rspec_parallel": "\ue21e", // 
".rspec_status": "\ue21e", //  ".rspec_status": "\ue21e", // 
".rss": "\uf09e", //  ".rss": "\uf09e", // 
".rtf": "\uf718", // ".rtf": "\U000f0219", // 󰈙
".ru": "\ue21e", //  ".ru": "\ue21e", // 
".rubydoc": "\ue73b", //  ".rubydoc": "\ue73b", // 
".sass": "\ue603", //  ".sass": "\ue603", // 
@ -290,7 +290,7 @@ var extIconMap = map[string]string{
".tzo": "\uf410", //  ".tzo": "\uf410", // 
".video": "\uf03d", //  ".video": "\uf03d", // 
".vim": "\ue62b", //  ".vim": "\ue62b", // 
".vue": "\ufd42", // ".vue": "\U000f0844", // 󰡄
".war": "\ue256", //  ".war": "\ue256", // 
".wav": "\uf001", //  ".wav": "\uf001", // 
".webm": "\uf03d", //  ".webm": "\uf03d", // 
@ -313,6 +313,16 @@ var extIconMap = map[string]string{
".zst": "\uf410", //  ".zst": "\uf410", // 
} }
func patchFileIconsForNerdFontsV2() {
extIconMap[".cs"] = "\uf81a" // 
extIconMap[".csproj"] = "\uf81a" // 
extIconMap[".csx"] = "\uf81a" // 
extIconMap[".license"] = "\uf718" // 
extIconMap[".node"] = "\uf898" // 
extIconMap[".rtf"] = "\uf718" // 
extIconMap[".vue"] = "\ufd42" // ﵂
}
func IconForFile(name string, isSubmodule bool, isDirectory bool) string { func IconForFile(name string, isSubmodule bool, isDirectory bool) string {
base := filepath.Base(name) base := filepath.Base(name)
if icon, ok := nameIconMap[base]; ok { if icon, ok := nameIconMap[base]; ok {

View File

@ -6,26 +6,30 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
) )
const ( var (
BRANCH_ICON = "\ufb2b" // BRANCH_ICON = "\U000f062c" // 󰘬
DETACHED_HEAD_ICON = "\ue729" //  DETACHED_HEAD_ICON = "\ue729" // 
TAG_ICON = "\uf02b" //  TAG_ICON = "\uf02b" // 
COMMIT_ICON = "\ufc16" // COMMIT_ICON = "\U000f0718" // 󰜘
MERGE_COMMIT_ICON = "\ufb2c" // MERGE_COMMIT_ICON = "\U000f062d" // 󰘭
DEFAULT_REMOTE_ICON = "\uf7a1" // DEFAULT_REMOTE_ICON = "\uf02a2" // 󰊢
STASH_ICON = "\uf01c" //  STASH_ICON = "\uf01c" // 
) )
type remoteIcon struct { var remoteIcons = map[string]string{
domain string "github.com": "\ue709", // 
icon string "bitbucket.org": "\ue703", // 
"gitlab.com": "\uf296", // 
"dev.azure.com": "\U000f0805", // 󰠅
} }
var remoteIcons = []remoteIcon{ func patchGitIconsForNerdFontsV2() {
{domain: "github.com", icon: "\ue709"}, // BRANCH_ICON = "\ufb2b" //
{domain: "bitbucket.org", icon: "\ue703"}, // COMMIT_ICON = "\ufc16" //
{domain: "gitlab.com", icon: "\uf296"}, // MERGE_COMMIT_ICON = "\ufb2c" //
{domain: "dev.azure.com", icon: "\ufd03"}, // DEFAULT_REMOTE_ICON = "\uf7a1" //
remoteIcons["dev.azure.com"] = "\ufd03" // ﴃ
} }
func IconForBranch(branch *models.Branch) string { func IconForBranch(branch *models.Branch) string {
@ -51,10 +55,10 @@ func IconForCommit(commit *models.Commit) string {
} }
func IconForRemote(remote *models.Remote) string { func IconForRemote(remote *models.Remote) string {
for _, r := range remoteIcons { for domain, icon := range remoteIcons {
for _, url := range remote.Urls { for _, url := range remote.Urls {
if strings.Contains(url, r.domain) { if strings.Contains(url, domain) {
return r.icon return icon
} }
} }
} }

View File

@ -1,11 +1,26 @@
package icons package icons
import (
"log"
"github.com/samber/lo"
)
var isIconEnabled = false var isIconEnabled = false
func IsIconEnabled() bool { func IsIconEnabled() bool {
return isIconEnabled return isIconEnabled
} }
func SetIconEnabled(showIcons bool) { func SetNerdFontsVersion(version string) {
isIconEnabled = showIcons if !lo.Contains([]string{"2", "3"}, version) {
log.Fatalf("Unsupported nerdFontVersion %s", version)
}
if version == "2" {
patchGitIconsForNerdFontsV2()
patchFileIconsForNerdFontsV2()
}
isIconEnabled = true
} }