Add the pager config option

This commit is contained in:
Mislav Marohnić 2020-09-16 16:15:37 +02:00
parent c643778701
commit f6dd1bcd0a
4 changed files with 20 additions and 3 deletions

View file

@ -51,12 +51,14 @@ func main() {
os.Exit(2)
}
prompt, _ := cfg.Get("", "prompt")
if prompt == config.PromptsDisabled {
if prompt, _ := cfg.Get("", "prompt"); prompt == config.PromptsDisabled {
cmdFactory.IOStreams.SetNeverPrompt(true)
}
if pager, _ := cfg.Get("", "pager"); pager != "" {
cmdFactory.IOStreams.SetPager(pager)
}
expandedArgs := []string{}
if len(os.Args) > 0 {
expandedArgs = os.Args[1:]

View file

@ -180,6 +180,15 @@ func NewBlankRoot() *yaml.Node {
Kind: yaml.ScalarNode,
Value: PromptsEnabled,
},
{
HeadComment: "A pager program to send command output to. Example value: less",
Kind: yaml.ScalarNode,
Value: "pager",
},
{
Kind: yaml.ScalarNode,
Value: "",
},
{
HeadComment: "Aliases allow you to create nicknames for gh commands",
Kind: yaml.ScalarNode,

View file

@ -45,6 +45,8 @@ func Test_defaultConfig(t *testing.T) {
editor:
# When to interactively prompt. This is a global config that cannot be overriden by hostname. Supported values: enabled, disabled
prompt: enabled
# A pager program to send command output to. Example value: less
pager:
# Aliases allow you to create nicknames for gh commands
aliases:
co: pr checkout

View file

@ -92,6 +92,10 @@ func (s *IOStreams) IsStderrTTY() bool {
return false
}
func (s *IOStreams) SetPager(cmd string) {
s.pagerCommand = cmd
}
func (s *IOStreams) StartPager() error {
if s.pagerCommand == "" || !s.IsStdoutTTY() {
return nil