2022-08-07 16:16:52 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2022-08-09 02:37:27 +02:00
|
|
|
"runtime"
|
2022-08-07 16:16:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Pager attempts to locate a pager that's appropriate for the environment.
|
|
|
|
func Pager() string {
|
|
|
|
|
2022-08-09 02:37:27 +02:00
|
|
|
// default to `more` on Windows
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return "more"
|
|
|
|
}
|
|
|
|
|
2022-08-07 16:16:52 +02:00
|
|
|
// if $PAGER is set, return the corresponding pager
|
|
|
|
if os.Getenv("PAGER") != "" {
|
|
|
|
return os.Getenv("PAGER")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, search for `pager`, `less`, and `more` on the `$PATH`. If
|
|
|
|
// none are found, return an empty pager.
|
|
|
|
for _, pager := range []string{"pager", "less", "more"} {
|
|
|
|
if path, err := exec.LookPath(pager); err != nil {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// default to no pager
|
|
|
|
return ""
|
|
|
|
}
|