about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-12-10T17·16+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-12-10T17·16+0100
commitc56bfbe863322fe9d5d5748681ebcc0de7780c02 (patch)
tree8d8e7ee6367839bd70127b5c5bb795943020b984 /src
parent851b47bd7de35f4464a67c991d55cbcb07230edc (diff)
Provide default pagers
Borrowed from systemd.
Diffstat (limited to 'src')
-rw-r--r--src/libmain/shared.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 1d50346a1bf8..8d06455fa739 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -291,8 +291,9 @@ int handleExceptions(const string & programName, std::function<void()> fun)
 
 RunPager::RunPager()
 {
-    string pager = getEnv("PAGER");
-    if (!isatty(STDOUT_FILENO) || pager.empty()) return;
+    if (!isatty(STDOUT_FILENO)) return;
+    string pager = getEnv("PAGER", "default");
+    if (pager == "" || pager == "cat") return;
 
     /* Ignore SIGINT. The pager will handle it (and we'll get
        SIGPIPE). */
@@ -312,7 +313,11 @@ RunPager::RunPager()
             throw SysError("dupping stdin");
         if (!getenv("LESS"))
             setenv("LESS", "FRSXMK", 1);
-        execl("/bin/sh", "sh", "-c", pager.c_str(), NULL);
+        if (pager != "default")
+            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);
     });