You are not logged in.

#1 2017-06-26 07:28:09

stupidus
Member
Registered: 2012-02-27
Posts: 124

[Solved] systemctl and journalctl with mouse scroll

I would like to be able to use use my touchpad to scroll through the journalctl output, like I can do with normal less. I figured out that I can configure the less options that journalctl uses by setting $SYSTEMD_LESS. By default it is set to "FRSXMK". By removing the X (so "FRSMK"), I am able to scroll through the output. However, if the output is very short (like for systemctl --user status), there is no output at all with this setting. Is there a way to configure systemctl and journalctl, to both display short outputs and enable mouse scrolling in long outputs?

I know, I can call systemctl/journalctl with --no-pager, but that requires me to know beforehand how long the output will be.

Last edited by stupidus (2017-06-27 08:27:52)

Offline

#2 2017-06-26 07:46:51

SmallAndSimple
Member
Registered: 2015-11-25
Posts: 58

Re: [Solved] systemctl and journalctl with mouse scroll

So, if you use

journalctl -xe

Then what exactly are your issues with what happens next?

Offline

#3 2017-06-26 08:12:19

stupidus
Member
Registered: 2012-02-27
Posts: 124

Re: [Solved] systemctl and journalctl with mouse scroll

Without setting $SYSTEMD_LESS then journalctl -xe show the journalctl output using less, but I can only scroll with j/k or the arrow keys. If I set $SYSTEMD_LESS to "FRSMK", then it shows the same output, but I can also scroll using the touchpad, which is what I prefer. However, calling "systemctl --user status" with the same value for $SYSTEMD_LESS shows no output. To see the output, I have either to set $SYSTEMD_LESS back to the default or use the --no-pager option. Basically, I think that I am looking for the right options for less to be able to scroll using the mouse, but still have short output being shown.

BTW, I am using termite as my terminal emulator, though I don't think that it matters, as the behaviour is the same with xterm.

Offline

#4 2017-06-26 08:45:19

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: [Solved] systemctl and journalctl with mouse scroll

I don't use the X, F and K options:

$ echo $SYSTEMD_LESS
j.25MqRSW#.25

Does this change something for you?

Offline

#5 2017-06-26 11:45:07

stupidus
Member
Registered: 2012-02-27
Posts: 124

Re: [Solved] systemctl and journalctl with mouse scroll

Thank you. Removing the F option did the trick, I kept the K option though, because else less becomes unresponsive if you scroll above the beginning or below the end of the output.

However, I kind of liked the idea, that it would just display the output if it is short, without going into the alternate screen.

I tried to solve this with a wrapper script:

#!/bin/bash

length=$(wc -l $1)
if (("$length" > "40")); then
    echo $1 | less -RSMK
else
    echo $1 | less -FRSMKX
fi

Using `journalctl --no-pager | my-script` will open less without any output, whereas `systemctl --user status --no-pager | my-script` will not display anything. So, if detects the number of lines correctly, but the `echo $1 | less` part does not work.

Offline

#6 2017-06-26 15:03:40

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: [Solved] systemctl and journalctl with mouse scroll

Your script will not work as you expect it to.
This one should do what you want:

#!/bin/bash

TMPDIR=$HOME/tmp

length=$(wc -l $TMPDIR/systemdout.txt|cut -d' ' -f1)
if ((length > 40)); then
    less -RSMK $TMPDIR/systemdout.txt
else
    less -FRSMKX $TMPDIR/systemdout.txt
fi

The script is $HOME/tmp/systemdless and you use it like that:

journalctl --no-pager -b >$HOME/tmp/systemdout.txt && $HOME/tmp/systemdless

systemctl --user status --no-pager >$HOME/tmp/systemdout.txt && $HOME/tmp/systemdless

Last edited by berbae (2017-06-27 07:58:18)

Offline

#7 2017-06-27 08:27:31

stupidus
Member
Registered: 2012-02-27
Posts: 124

Re: [Solved] systemctl and journalctl with mouse scroll

Thanks for the input.
However, as I would like to avoid using temporary files I managed to find a way to make my script work:

#!/bin/bash

input=$(tee)
length=$(echo "$input" | wc -l)
if (("$length" > "40")); then
    echo "$input" | less -RSMK
else
    echo "$input"
fi

This solution may not be very elegant, but it seems to work.

Offline

Board footer

Powered by FluxBB