[systemd-devel] [PATCH] pager: support SYSTEMD_LESS environment variable

Jason A. Donenfeld Jason at zx2c4.com
Tue Feb 11 17:58:23 PST 2014


This allows customization of the arguments used by less. The main
motivation is that some folks might not like having --no-init on every
invocation of less.
---
If you'd like me to update some documentation, let me know what
files I should edit, and I'll send a v2.

 src/shared/pager.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/shared/pager.c b/src/shared/pager.c
index 72a29f2..4a7be4e 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -50,6 +50,8 @@ noreturn static void pager_fallback(void) {
 int pager_open(bool jump_to_end) {
         int fd[2];
         const char *pager;
+        char *less_opts;
+        _cleanup_free_ *joined_less_opts = NULL;
         pid_t parent_pid;
         int r;
 
@@ -88,10 +90,17 @@ int pager_open(bool jump_to_end) {
                 dup2(fd[0], STDIN_FILENO);
                 close_pipe(fd);
 
-                if (jump_to_end)
-                        setenv("LESS", "FRSXMK+G", 1);
-                else
-                        setenv("LESS", "FRSXMK", 1);
+                less_opts = getenv("SYSTEMD_LESS");
+                if (!less_opts) {
+                        if (jump_to_end)
+                                less_opts = "FRSXMK+G";
+                        else
+                                less_opts = "FRSXMK";
+                } else if (jump_to_end) {
+                        joined_less_opts = strjoin(less_opts, " +G", NULL);
+                        less_opts = joined_less_opts;
+                }
+                setenv("LESS", less_opts, 1);
 
                 /* Make sure the pager goes away when the parent dies */
                 if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
-- 
1.8.5.4



More information about the systemd-devel mailing list