make systemd pager not do horizontal scroll, and wrap to next line instead

By default systemd (v245) on Ubuntu 20.04 focal, if I do systemctl status $THING, and the output lines are longer than my screen, then the default pager (less?) will do horizontal scrolling. I would rather the extra text be on the following lines ("word wrap")

what environmental variable can I set to make this change from horizontal scrolling to "put the remainder of the line on the next line"?

I know that systemctl --no-pager $THING or systemctl status $THING | cat will work in this case, but that's extra text to type every time. I want systemctl status $THING to always work without having to add extra bits.


Solution 1:

By default, systemctl spawns less as the pager (if it is available, but on most systems, it is). In this case, less is given the parameters FRSXMK, of which S is responsible for not folding long lines.

If the SYSTEMD_LESS environment variable is set, its contents are handled as the flags to be given to less, if less is the pager currently in use. So if you omit the S flag from the variable, and do an

export SYSTEMD_LESS="FRXMK"

then systemctl will behave exactly as before, except it will fold long lines.

It might be worth noting that you can switch line folding within less by typing -S and pressing enter.

Solution 2:

You can make no-pager permanent by exporting an empty environment variable SYSTEMD_PAGER, i.e.:

export SYSTEMD_PAGER=

But you will notice that now systemd ellipsizes the long lines, so you must also turn this off with the -l, --full command line option. There's no environment variable to change this, unfortunately.


For a complete solution I would suggest a shell alias for systemctl, such as:

alias systemctl='systemctl --no-pager --full'