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-10-23 00:52:19 +02:00
|
|
|
output := c.GitConfig.Get("core.pager")
|
|
|
|
return strings.Split(output, "\n")[0]
|
2020-09-29 12:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GitCommand) GetPager(width int) string {
|
2021-12-29 02:41:33 +02:00
|
|
|
useConfig := c.UserConfig.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),
|
|
|
|
}
|
|
|
|
|
2021-12-29 02:41:33 +02:00
|
|
|
pagerTemplate := c.UserConfig.Git.Paging.Pager
|
2020-09-29 12:03:39 +02:00
|
|
|
return utils.ResolvePlaceholderString(pagerTemplate, templateValues)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GitCommand) colorArg() string {
|
2021-12-29 02:41:33 +02:00
|
|
|
return c.UserConfig.Git.Paging.ColorArg
|
2020-09-29 12:03:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 03:40:42 +02:00
|
|
|
// UsingGpg tells us whether the user has gpg enabled so that we can know
|
|
|
|
// whether we need to run a subprocess to allow them to enter their password
|
|
|
|
func (c *GitCommand) UsingGpg() bool {
|
2021-12-29 02:41:33 +02:00
|
|
|
overrideGpg := c.UserConfig.Git.OverrideGpg
|
2021-04-10 03:40:42 +02:00
|
|
|
if overrideGpg {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-23 00:52:19 +02:00
|
|
|
return c.GitConfig.GetBool("commit.gpgsign")
|
2021-04-10 03:40:42 +02:00
|
|
|
}
|