Prevent endless recursive pager

Unset PAGER environment variable when executing the command referenced
in PAGER in case that command also has support for PAGER and would end
up executing itself indefinitely.
This commit is contained in:
Mislav Marohnić 2020-09-14 16:49:30 +02:00
parent 6ad6784c46
commit 76181156ba

View file

@ -103,6 +103,11 @@ func (s *IOStreams) StartPager() error {
}
pagerEnv := os.Environ()
for i := len(pagerEnv) - 1; i >= 0; i-- {
if strings.HasPrefix(pagerEnv[i], "PAGER=") {
pagerEnv = append(pagerEnv[0:i], pagerEnv[i+1:]...)
}
}
if _, ok := os.LookupEnv("LESS"); !ok {
pagerEnv = append(pagerEnv, "LESS=FRX")
}