i3status-rust icon indicating copy to clipboard operation
i3status-rust copied to clipboard

if_command_interval for reverifying if_command

Open ad-fabiane opened this issue 2 years ago • 9 comments

Hi, i just installed v0.30 and i really like it.

I am running i3 on a laptop and i often travel between different workplaces, but i still want my network interfaces monitored. I came up with the following solution:

[[block]]
block = "net"
if_command = "cat /sys/class/net/eno2/operstate | grep -q down && cat /sys/class/net/wlo1/operstate | grep -q up"
device = "^wlo1$"
format = " $speed_down:$graph_down:down $speed_up:$graph_up:up "
format_alt = " $device {$ip|$ipv6} "

[[block]]
block = "net"
if_command = "cat /sys/class/net/eno2/operstate | grep -q up"
device = "^eno2$"
format = " $speed_down:$graph_down:down $speed_up:$graph_up:up "
format_alt = " $device {$ip|$ipv6} "

# block with eventual vpn connection

[[block]]
block = "net"
if_command = "cat /sys/class/net/wlo1/operstate | grep -q down && cat /sys/class/net/eno2/operstate | grep -q down"
device = "^x$" # This is supposed to be non-existent
missing_format = " No connection found..."
[[block.click]]
button = "left"
cmd = "nmcli device up wlo1" # Your command to rescan and connect to network

The problem is that if_command is run on startup. Sure i could write scripts that will reload i3, but i am sure there are other ways to make use of this.

I suggest if_command_interval to be 0 (disabled) by default and configurable in per block configuration. I tried implementing this myself, but i am not at all experienced and I'm not sure about the cleanest way to do this.

If someone could point me in the right direction, i would be happy to participate to this project. Keep up the great Work

ad-fabiane avatar Feb 23 '23 23:02 ad-fabiane

Does missing_format = "" without any ifs on those blocks not cover this use case? Your current config also doesn't show any block if both interfaces are up, is that correct?

Besides that, an if_command_interval might still be an interesting feature, wdyt @MaxVerevkin ?

GladOSkar avatar Feb 23 '23 23:02 GladOSkar

With #1758 this could be a singe block:

[[block]]
block = "net"
device = "^(wlo1|eno2)$"
format = " $speed_down:$graph_down:down $speed_up:$graph_up:up "
format_alt = " $device {$ip|$ipv6} "
missing_format = " No connection found..."

Besides that, an if_command_interval might still be an interesting feature

Maybe. But I feel like most of the time, if you need something like that it is better to implement this feature in the block.

MaxVerevkin avatar Feb 24 '23 09:02 MaxVerevkin

for better performance i decided to disable my docker daemon. And if its not active the block would fail. With if_command_interval i could do something like this:

[[block]]
block = "docker"
if_command = "test -e /var/run/docker.sock"
if_command_interval = 30
format = "  running: ... $..."

[[block]]
block = "docker"
format = "docker daemon not running"
if_command = "test ! -e /var/run/docker.sock" # check if docker is still NOT running
if_command_interval = 30
[[block.click]]
button = "left"
cmd = "rc-service docker start" # systemctl start docker

you would have the option of "custom errors" and fixing them with 1 click.

ad-fabiane avatar Feb 24 '23 11:02 ad-fabiane

And if its not active the block would fail.

It doesn't fail. It displays error_format and it retries again after error_interval seconds.

MaxVerevkin avatar Feb 24 '23 12:02 MaxVerevkin

So the only advantage this would bring with it is to be able to run a cmd in [[block.click]]. Another approach this this might be error_button and error_cmd.

[[block]]
block = "docker"
error_format = "docker daemon not running ..."
error_interval = 30 
error_button = "left"
error_cmd = "rc-service docker start" # systemctl start docker

In the future maybe even make [block.error] a new table with error_format, error_fullscreen_format, error_interval and the two just named.

[[block]]
block = "docker"
[block.error]
...

What is your opinion on this?

ad-fabiane avatar Feb 24 '23 15:02 ad-fabiane

[[block]]
block = "docker"
format = "docker daemon not running"
if_command = "test ! -e /var/run/docker.sock" # check if docker is still NOT running
if_command_interval = 30
[[block.click]]
button = "left"
cmd = "rc-service docker start" # systemctl start docker

I don't think this would even work. If docker is not running, this block would just output an error message.

You can however do this using custom block.

Another approach this this might be error_button and error_cmd

That's interesting. However I have some concerns. Mainly, an error can occur for a number of reasons, not only because docker is not running.

MaxVerevkin avatar Feb 24 '23 18:02 MaxVerevkin

For me I'd like the if_command to be rerun at an interval because I could then use it to conditionally display the disk space block only when below a certain threshold. Or only display the cpu/memory/temperature when above a certain threshold.

ismay avatar Apr 11 '24 11:04 ismay

For me I'd like the if_command to be rerun at an interval because I could then use it to conditionally display the disk space block only when below a certain threshold. Or only display the cpu/memory/temperature when above a certain threshold.

I think that this would be better suited by the proposed allow argument in #1957 so that you don't have to query the information through the block and a shell command.

bim9262 avatar Apr 11 '24 14:04 bim9262

Yeah if that would allow me to hide a block on values above or below a certain threshold that'd work for me as well 👍.

ismay avatar Apr 11 '24 15:04 ismay