charmbracelet/glow · error

unable to parse PAGER command: %s

Error message

unable to parse PAGER command: %s

What it means

When output goes through a pager (pager true or --pager changed), glow reads PAGER (defaulting to "less -r") and tokenizes it with shell.Fields from mvdan.cc/sh/v3 - a POSIX-style field splitter that honors quotes and variable expansion. This error means tokenization failed or produced no fields: the PAGER value is not a syntactically valid shell command line. The message includes the raw PAGER string so you can see what failed to parse.

Source

Thrown at main.go:324

		content = utils.WrapCodeBlock(string(b), ext)
	}

	out, err := r.Render(content)
	if err != nil {
		return fmt.Errorf("unable to render markdown: %w", err)
	}

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

		fields, err := shell.Fields(pagerCmd, os.Getenv)
		if err != nil || len(fields) == 0 {
			return fmt.Errorf("unable to parse PAGER command: %s", pagerCmd)
		}
		c := exec.Command(fields[0], fields[1:]...) //nolint:gosec
		c.Stdin = strings.NewReader(out)
		c.Stdout = os.Stdout
		if err := c.Run(); err != nil {
			return fmt.Errorf("unable to run command: %w", err)
		}
		return nil
	case tui || cmd.Flags().Changed("tui"):
		path := ""
		if !isURL(src.URL) {
			path = src.URL
		}
		return runTUI(path, content)
	default:
		if _, err = fmt.Fprint(w, out); err != nil {
			return fmt.Errorf("unable to write to writer: %w", err)
		}

View on GitHub (pinned to e3970c813d)

Solutions

  1. Check PAGER for unbalanced quotes or stray characters: echo "$PAGER"
  2. Set a simple known-good value: export PAGER='less -r'
  3. Temporarily unset PAGER (unset PAGER) to confirm it is the cause
  4. Use straight ASCII quotes, not typographic ones, in shell configs

Example fix

# before
export PAGER='less -r"   # unbalanced quote

# after
export PAGER='less -r'
Defensive patterns

Strategy: validation

Validate before calling

func pagerParses(pagerCmd string) bool {
	fields, err := shell.Fields(pagerCmd, os.Getenv)
	return err == nil && len(fields) > 0
}

Prevention

When it happens

Trigger: Unbalanced quotes in PAGER (PAGER='less -r"), stray backslashes, or expansion errors inside the PAGER string; a PAGER that expands to an empty command line.

Common situations: User shell configs exporting PAGER with quoting mistakes, values copied from tutorials with smart/curly quotes, templates injecting broken quoting into PAGER.

Understand the failure class

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/deef51fb7cd773ff. Report an issue: GitHub.