Skip to content

Commit f6dd1bc

Browse files
committed
Add the pager config option
1 parent c643778 commit f6dd1bc

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

cmd/gh/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ func main() {
5151
os.Exit(2)
5252
}
5353

54-
prompt, _ := cfg.Get("", "prompt")
55-
56-
if prompt == config.PromptsDisabled {
54+
if prompt, _ := cfg.Get("", "prompt"); prompt == config.PromptsDisabled {
5755
cmdFactory.IOStreams.SetNeverPrompt(true)
5856
}
5957

58+
if pager, _ := cfg.Get("", "pager"); pager != "" {
59+
cmdFactory.IOStreams.SetPager(pager)
60+
}
61+
6062
expandedArgs := []string{}
6163
if len(os.Args) > 0 {
6264
expandedArgs = os.Args[1:]

internal/config/config_type.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ func NewBlankRoot() *yaml.Node {
180180
Kind: yaml.ScalarNode,
181181
Value: PromptsEnabled,
182182
},
183+
{
184+
HeadComment: "A pager program to send command output to. Example value: less",
185+
Kind: yaml.ScalarNode,
186+
Value: "pager",
187+
},
188+
{
189+
Kind: yaml.ScalarNode,
190+
Value: "",
191+
},
183192
{
184193
HeadComment: "Aliases allow you to create nicknames for gh commands",
185194
Kind: yaml.ScalarNode,

internal/config/config_type_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func Test_defaultConfig(t *testing.T) {
4545
editor:
4646
# When to interactively prompt. This is a global config that cannot be overriden by hostname. Supported values: enabled, disabled
4747
prompt: enabled
48+
# A pager program to send command output to. Example value: less
49+
pager:
4850
# Aliases allow you to create nicknames for gh commands
4951
aliases:
5052
co: pr checkout

pkg/iostreams/iostreams.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func (s *IOStreams) IsStderrTTY() bool {
9292
return false
9393
}
9494

95+
func (s *IOStreams) SetPager(cmd string) {
96+
s.pagerCommand = cmd
97+
}
98+
9599
func (s *IOStreams) StartPager() error {
96100
if s.pagerCommand == "" || !s.IsStdoutTTY() {
97101
return nil

0 commit comments

Comments
 (0)