Skip to content

Commit

Permalink
Enable/Disable pager from config (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat authored Feb 4, 2021
1 parent 2088bac commit 3285903
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func validateOptions(cmd *cobra.Command) error {
width = viper.GetUint("width")
localOnly = viper.GetBool("local")
mouse = viper.GetBool("mouse")
pager = viper.GetBool("pager")

// validate the glamour style
style = viper.GetString("style")
Expand Down Expand Up @@ -270,13 +271,13 @@ func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
}

// display
if cmd.Flags().Changed("pager") {
pager := os.Getenv("PAGER")
if pager == "" {
pager = "less -r"
if pager || cmd.Flags().Changed("pager") {
pagerCmd := os.Getenv("PAGER")
if pagerCmd == "" {
pagerCmd = "less -r"
}

pa := strings.Split(pager, " ")
pa := strings.Split(pagerCmd, " ")
c := exec.Command(pa[0], pa[1:]...)
c.Stdin = strings.NewReader(content)
c.Stdout = os.Stdout
Expand Down

0 comments on commit 3285903

Please sign in to comment.