On Wed, Jan 25, 2017 at 06:45:42PM +0100, Andreas Henriksson wrote:
[...]
> Another option might be to make the util-linux build system
> detect full path of less during configure, then add code to
> check if the file exists or bail out early at:
> http://sources.debian.net/src/util-linux/2.29.1-1/lib/pager.c/#L59
[...]

A lazy version of that is attached (ie. no configure integration).
Maybe we can sucker upstream into taking that patch (which should be a
no-change normally but) to make it possible for us do:
make CFLAGS="-DDEFAULT_SHELL_FULLPATH=/usr/bin/sensible-pager"

Improvements welcome.

Regards,
Andreas Henriksson
diff --git a/lib/pager.c b/lib/pager.c
index 114b3f7a7..4fe7970ce 100644
--- a/lib/pager.c
+++ b/lib/pager.c
@@ -170,6 +170,20 @@ static void wait_for_pager_signal(int signo)
 	raise(signo);
 }
 
+static char* get_default_pager(void)
+{
+#ifdef DEFAULT_PAGER_FULLPATH
+#define STRING(x) #x
+#define STRING_OF(x) STRING(x)
+	if (access(STRING_OF(DEFAULT_PAGER_FULLPATH), F_OK) == 0)
+		return STRING_OF(DEFAULT_PAGER_FULLPATH);
+#else
+	return "less";
+#endif
+	return NULL;
+}
+
+
 static void __setup_pager(void)
 {
 	const char *pager = getenv("PAGER");
@@ -178,9 +192,11 @@ static void __setup_pager(void)
 	if (!isatty(STDOUT_FILENO))
 		return;
 
-	if (!pager)
-		pager = "less";
-	else if (!*pager || !strcmp(pager, "cat"))
+	if (!pager) {
+		pager = get_default_pager();
+		if (!pager)
+			return;
+	} else if (!*pager || !strcmp(pager, "cat"))
 		return;
 
 	/* spawn the pager */

Reply via email to