[systemd-devel] [PATCH v2] pager: support SYSTEMD_LESS environment variable
Jason A. Donenfeld
Jason at zx2c4.com
Tue Feb 11 18:30:10 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.
---
man/journalctl.xml | 4 ++++
man/localectl.xml | 4 ++++
man/loginctl.xml | 4 ++++
man/machinectl.xml | 4 ++++
man/systemctl.xml | 4 ++++
man/systemd-analyze.xml | 4 ++++
man/timedatectl.xml | 4 ++++
src/shared/pager.c | 19 ++++++++++++++-----
8 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/man/journalctl.xml b/man/journalctl.xml
index 3b05e80..18a1b9e 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -887,6 +887,10 @@
this to an empty string or the value
<literal>cat</literal> is equivalent to passing
<option>--no-pager</option>.</para></listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/localectl.xml b/man/localectl.xml
index 0950cce..238757c 100644
--- a/man/localectl.xml
+++ b/man/localectl.xml
@@ -265,6 +265,10 @@
this to an empty string or the value
<literal>cat</literal> is equivalent to passing
<option>--no-pager</option>.</para></listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/loginctl.xml b/man/loginctl.xml
index 13105d4..ede869f 100644
--- a/man/loginctl.xml
+++ b/man/loginctl.xml
@@ -486,6 +486,10 @@
this to an empty string or the value
<literal>cat</literal> is equivalent to passing
<option>--no-pager</option>.</para></listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/machinectl.xml b/man/machinectl.xml
index 6e991ee..1f272a8 100644
--- a/man/machinectl.xml
+++ b/man/machinectl.xml
@@ -299,6 +299,10 @@
this to an empty string or the value
<literal>cat</literal> is equivalent to passing
<option>--no-pager</option>.</para></listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/systemctl.xml b/man/systemctl.xml
index ed1bf48..1b0f8e5 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1479,6 +1479,10 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
equivalent to passing
<option>--no-pager</option>.</para>
</listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml
index cbf59e0..54479e4 100644
--- a/man/systemd-analyze.xml
+++ b/man/systemd-analyze.xml
@@ -335,6 +335,10 @@ $ eog targets.svg</programlisting>
equivalent to passing
<option>--no-pager</option>.</para>
</listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/man/timedatectl.xml b/man/timedatectl.xml
index beda304..be66993 100644
--- a/man/timedatectl.xml
+++ b/man/timedatectl.xml
@@ -239,6 +239,10 @@
this to an empty string or the value
<literal>cat</literal> is equivalent to passing
<option>--no-pager</option>.</para></listitem>
+ <term><varname>$SYSTEMD_LESS</varname></term>
+ <listitem><para><varname>$SYSTEMD_LESS</varname> overrides the
+ default options passed to <literal>less</literal>
+ (<literal>FRSXMK</literal>).</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 72a29f2..46eebc8 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -49,7 +49,8 @@ noreturn static void pager_fallback(void) {
int pager_open(bool jump_to_end) {
int fd[2];
- const char *pager;
+ const char *pager, *less_opts;
+ _cleanup_free_ char *joined_less_opts = NULL;
pid_t parent_pid;
int r;
@@ -88,10 +89,18 @@ 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 = strappend(less_opts, " +G");
+ if (joined_less_opts)
+ 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