mirror of
https://github.com/cheat/cheat.git
synced 2024-12-18 10:45:05 +01:00
33 lines
644 B
Go
33 lines
644 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
)
|
|
|
|
// Pager attempts to locate a pager that's appropriate for the environment.
|
|
func Pager() string {
|
|
|
|
// default to `more` on Windows
|
|
if runtime.GOOS == "windows" {
|
|
return "more"
|
|
}
|
|
|
|
// 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 ""
|
|
}
|