diff --git a/cmd/gh/main.go b/cmd/gh/main.go index fdde7acd3..73b153ffa 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -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:] diff --git a/internal/config/config_type.go b/internal/config/config_type.go index 740955539..2ff23e58c 100644 --- a/internal/config/config_type.go +++ b/internal/config/config_type.go @@ -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, diff --git a/internal/config/config_type_test.go b/internal/config/config_type_test.go index 1e1122c78..50e2b9f5a 100644 --- a/internal/config/config_type_test.go +++ b/internal/config/config_type_test.go @@ -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 diff --git a/pkg/iostreams/iostreams.go b/pkg/iostreams/iostreams.go index e3694dfe5..d6c8ae48f 100644 --- a/pkg/iostreams/iostreams.go +++ b/pkg/iostreams/iostreams.go @@ -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