Skip to content

Commit

Permalink
Merge pull request #1 from mr-pmillz/gitconfig_optimize
Browse files Browse the repository at this point in the history
Enhanced ini style config embedded file
  • Loading branch information
mr-pmillz authored Oct 16, 2021
2 parents f88fbad + ef516a7 commit 848784f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
46 changes: 43 additions & 3 deletions extra/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"pimp-my-shell/githubapi"
"pimp-my-shell/localio"
"gopkg.in/ini.v1"
)

//go:embed templates/*
Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion extra/templates/.gitconfig
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 848784f

Please sign in to comment.