mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-12 07:10:26 +00:00
Add FixPagerEnv
This commit is contained in:
parent
ac725d419b
commit
b4dc9c9f75
21
z/page.go
21
z/page.go
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/rwxrob/to"
|
||||
)
|
||||
@ -11,6 +12,25 @@ import (
|
||||
// NoPager disables all paging.
|
||||
var NoPager bool
|
||||
|
||||
// FixPagerEnv sets environment variables for
|
||||
// different pagers to get them to support color ANSI escapes. FRX is
|
||||
// added to LESS and LV is set to -c. (These are the same fixes used by
|
||||
// the git diff command.)
|
||||
func FixPagerEnv() {
|
||||
less := os.Getenv(`LESS`)
|
||||
if strings.Index(less, `R`) < 0 {
|
||||
less += `R`
|
||||
}
|
||||
if strings.Index(less, `F`) < 0 {
|
||||
less += `F`
|
||||
}
|
||||
if strings.Index(less, `X`) < 0 {
|
||||
less += `X`
|
||||
}
|
||||
os.Setenv(`LESS`, less)
|
||||
os.Setenv(`LV`, `-c`)
|
||||
}
|
||||
|
||||
// FindPager returns a full path to a pager binary if it can find one on
|
||||
// the system:
|
||||
//
|
||||
@ -22,6 +42,7 @@ func FindPager() string {
|
||||
if NoPager {
|
||||
return ""
|
||||
}
|
||||
FixPagerEnv()
|
||||
path := os.Getenv(`PAGER`)
|
||||
if path == "" {
|
||||
path, _ = exec.LookPath(path)
|
||||
|
Loading…
Reference in New Issue
Block a user