2020-09-29 12:03:39 +02:00
|
|
|
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")
|
|
|
|
}
|
2021-04-05 13:08:33 +02:00
|
|
|
output, err := c.RunCommandWithOutput("git config --get-all core.pager")
|
2020-09-29 12:03:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
trimmedOutput := strings.TrimSpace(output)
|
|
|
|
return strings.Split(trimmedOutput, "\n")[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GitCommand) GetPager(width int) string {
|
2020-10-03 06:54:55 +02:00
|
|
|
useConfig := c.Config.GetUserConfig().Git.Paging.UseConfig
|
2020-09-29 12:03:39 +02:00
|
|
|
if useConfig {
|
|
|
|
pager := c.ConfiguredPager()
|
|
|
|
return strings.Split(pager, "| less")[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
templateValues := map[string]string{
|
|
|
|
"columnWidth": strconv.Itoa(width/2 - 6),
|
|
|
|
}
|
|
|
|
|
2020-10-03 06:54:55 +02:00
|
|
|
pagerTemplate := c.Config.GetUserConfig().Git.Paging.Pager
|
2020-09-29 12:03:39 +02:00
|
|
|
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GitCommand) colorArg() string {
|
2020-10-03 06:54:55 +02:00
|
|
|
return c.Config.GetUserConfig().Git.Paging.ColorArg
|
2020-09-29 12:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GitCommand) GetConfigValue(key string) string {
|
2020-12-21 00:38:36 +02:00
|
|
|
output, _ := c.getGitConfigValue(key)
|
|
|
|
return output
|
2020-09-29 12:03:39 +02:00
|
|
|
}
|