From ef516a764a4e41a3b0b630d92de97d5a69c36fc1 Mon Sep 17 00:00:00 2001 From: Phillip Miller Date: Sat, 16 Oct 2021 01:51:34 -0400 Subject: [PATCH] Enhanced ini style config embedded file - Merge append --- CHANGELOG.md | 8 +++++++ extra/extra.go | 46 +++++++++++++++++++++++++++++++++++--- extra/templates/.gitconfig | 17 +++++++++++++- go.mod | 1 + go.sum | 2 ++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7110d5a..582f4a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v1.4.9](https://github.com/mr-pmillz/pimp-my-shell/tree/v1.4.9) (2021-10-15) + +[Full Changelog](https://github.com/mr-pmillz/pimp-my-shell/compare/v1.4.8...v1.4.9) + +## [v1.4.8](https://github.com/mr-pmillz/pimp-my-shell/tree/v1.4.8) (2021-10-14) + +[Full Changelog](https://github.com/mr-pmillz/pimp-my-shell/compare/v1.4.7...v1.4.8) + ## [v1.4.7](https://github.com/mr-pmillz/pimp-my-shell/tree/v1.4.7) (2021-10-14) [Full Changelog](https://github.com/mr-pmillz/pimp-my-shell/compare/46fee5ea2af5f58460e92aac4a8e1facc9c85fd9...v1.4.7) diff --git a/extra/extra.go b/extra/extra.go index 293c4a0..a24f4ca 100644 --- a/extra/extra.go +++ b/extra/extra.go @@ -5,6 +5,7 @@ import ( "fmt" "pimp-my-shell/githubapi" "pimp-my-shell/localio" + "gopkg.in/ini.v1" ) //go:embed templates/* @@ -130,14 +131,53 @@ func InstallExtraPackages(osType string, dirs *localio.Directories, packages *lo } } } + if err := updateGitConfig(); err != nil { + return err + } + + return nil +} - // update ~/.gitconfig with git-delta configurations +// updateGitConfig ... +func updateGitConfig() error { gitConfig, err := extraConfigs.ReadFile("templates/.gitconfig") if err != nil { return err } - if err := localio.EmbedFileStringAppendToDest(gitConfig, "~/.gitconfig"); err != nil { - return err + + exists, err := localio.Exists("~/.gitconfig") + if err == nil && !exists { + if err := localio.EmbedFileStringAppendToDest(gitConfig, "~/.gitconfig"); err != nil { + return err + } + } else if err == nil && exists { + gitConfigPath, err := localio.ResolveAbsPath("~/.gitconfig") + if err != nil { + return err + } + + opts := ini.LoadOptions{PreserveSurroundedQuote: true} + embeddedConfig, err := ini.LoadSources(opts, gitConfig) + if err != nil { + return err + } + + localGitConfig, err := ini.LoadSources(opts, gitConfigPath) + if err != nil { + return err + } + + sections := embeddedConfig.Sections() + for _, section := range sections { + keys := section.Keys() + for _, key := range keys { + localGitConfig.Section(section.Name()).Key(key.Name()).SetValue(key.Value()) + } + } + + if err := localGitConfig.SaveToIndent(gitConfigPath, " "); err != nil { + return err + } } return nil diff --git a/extra/templates/.gitconfig b/extra/templates/.gitconfig index 9d5c2ce..a5f5ae5 100644 --- a/extra/templates/.gitconfig +++ b/extra/templates/.gitconfig @@ -1,3 +1,19 @@ +[alias] + lo = log --oneline + lb = log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative -n 25 + lg = log --all --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=short -n 25 + lgd = log --all --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)(%an,%C(dim white) %ar)%Creset' --abbrev-commit --date=short -n 25 + ll = log --all --stat --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative -n 15 + compare = log --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(red)%d%C(reset)%C(white)[%cr]%C(reset) %x09%C(green)%an: %s %C(reset)' + l = log --all --graph --pretty=format:'%C(blue)%h%C(green)%d %s %C(dim white)(%aN, %ar)' + bl = log --graph --pretty=format:'%C(blue)%h%C(green)%d %s %C(dim white)(%aN, %ar)' + tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(red)%d%C(reset)\n %C(white)[%cr]%C(reset) %x09%C(green)%an: %s %C(reset)' + btree = log --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(red)%d%C(reset)\n %C(white)[%cr]%C(reset) %x09%C(green)%an: %s %C(reset)' + alias = config --get-regexp ^alias\\. + +[pull] + rebase = false + [pager] diff = delta log = delta @@ -20,5 +36,4 @@ file-style = omit hunk-header-decoration-style = blue box hunk-header-file-style = red - hunk-header-line-number-style = "#067a00" hunk-header-style = file line-number syntax \ No newline at end of file diff --git a/go.mod b/go.mod index ecd9988..82922a9 100644 --- a/go.mod +++ b/go.mod @@ -9,5 +9,6 @@ require ( github.com/klauspost/cpuid/v2 v2.0.9 github.com/schollz/progressbar/v3 v3.8.3 github.com/tidwall/gjson v1.9.1 + gopkg.in/ini.v1 v1.63.2 periph.io/x/periph v3.6.8+incompatible // indirect ) diff --git a/go.sum b/go.sum index ec7bfbe..4018833 100644 --- a/go.sum +++ b/go.sum @@ -63,6 +63,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c= +gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=