summaryrefslogtreecommitdiffstats
path: root/pkg/commands/config.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-09-29 20:03:39 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-09-29 20:48:49 +1000
commit72af7e41778bca93d82fa668641f515fba1d92bc (patch)
tree7e755e857be72205ee99641d5eb5d4556151ad8f /pkg/commands/config.go
parent1767f91047a35318f6b1e469199c8a7f547f2afc (diff)
factor out code from git.go
Diffstat (limited to 'pkg/commands/config.go')
-rw-r--r--pkg/commands/config.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/commands/config.go b/pkg/commands/config.go
new file mode 100644
index 000000000..018de2724
--- /dev/null
+++ b/pkg/commands/config.go
@@ -0,0 +1,52 @@
+package commands
+
+import (
+ "os"
+ "strconv"
+ "strings"
+
+ "github.com/jesseduffield/lazygit/pkg/utils"
+)
+
+func (c *GitCommand) ConfiguredPager() string {
+ if os.Getenv("GIT_PAGER") != "" {
+ return os.Getenv("GIT_PAGER")
+ }
+ if os.Getenv("PAGER") != "" {
+ return os.Getenv("PAGER")
+ }
+ output, err := c.OSCommand.RunCommandWithOutput("git config --get-all core.pager")
+ if err != nil {
+ return ""
+ }
+ trimmedOutput := strings.TrimSpace(output)
+ return strings.Split(trimmedOutput, "\n")[0]
+}
+
+func (c *GitCommand) GetPager(width int) string {
+ useConfig := c.Config.GetUserConfig().GetBool("git.paging.useConfig")
+ if useConfig {
+ pager := c.ConfiguredPager()
+ return strings.Split(pager, "| less")[0]
+ }
+
+ templateValues := map[string]string{
+ "columnWidth": strconv.Itoa(width/2 - 6),
+ }
+
+ pagerTemplate := c.Config.GetUserConfig().GetString("git.paging.pager")
+ return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
+}
+
+func (c *GitCommand) colorArg() string {
+ return c.Config.GetUserConfig().GetString("git.paging.colorArg")
+}
+
+func (c *GitCommand) GetConfigValue(key string) string {
+ output, err := c.OSCommand.RunCommandWithOutput("git config --get %s", key)
+ if err != nil {
+ // looks like this returns an error if there is no matching value which we're okay with
+ return ""
+ }
+ return strings.TrimSpace(output)
+}