Provide default pagers
Borrowed from systemd.
This commit is contained in:
parent
851b47bd7d
commit
c56bfbe863
1 changed files with 8 additions and 3 deletions
|
@ -291,8 +291,9 @@ int handleExceptions(const string & programName, std::function<void()> fun)
|
||||||
|
|
||||||
RunPager::RunPager()
|
RunPager::RunPager()
|
||||||
{
|
{
|
||||||
string pager = getEnv("PAGER");
|
if (!isatty(STDOUT_FILENO)) return;
|
||||||
if (!isatty(STDOUT_FILENO) || pager.empty()) return;
|
string pager = getEnv("PAGER", "default");
|
||||||
|
if (pager == "" || pager == "cat") return;
|
||||||
|
|
||||||
/* Ignore SIGINT. The pager will handle it (and we'll get
|
/* Ignore SIGINT. The pager will handle it (and we'll get
|
||||||
SIGPIPE). */
|
SIGPIPE). */
|
||||||
|
@ -312,7 +313,11 @@ RunPager::RunPager()
|
||||||
throw SysError("dupping stdin");
|
throw SysError("dupping stdin");
|
||||||
if (!getenv("LESS"))
|
if (!getenv("LESS"))
|
||||||
setenv("LESS", "FRSXMK", 1);
|
setenv("LESS", "FRSXMK", 1);
|
||||||
|
if (pager != "default")
|
||||||
execl("/bin/sh", "sh", "-c", pager.c_str(), NULL);
|
execl("/bin/sh", "sh", "-c", pager.c_str(), NULL);
|
||||||
|
execlp("pager", "pager", NULL);
|
||||||
|
execlp("less", "less", NULL);
|
||||||
|
execlp("more", "more", NULL);
|
||||||
throw SysError(format("executing ‘%1%’") % pager);
|
throw SysError(format("executing ‘%1%’") % pager);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue