brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

if_match not working #593

Closed bad-interpreter closed 6 years ago

bad-interpreter commented 6 years ago

My $apcupsd_status variable is "ONLINE". But if I do

${if_match "${apcupsd_status}" != "ONLINE"}NOT ONLINE${endif}

it will print "NOT ONLINE" too, in the same config. Is it a bug?

conky 1.10.8_pre compiled lun 16 lug 2018, 13.24.10, CEST for Linux 4.14.55-zion x86_64

Compiled in features:

System config file: /etc/conky/conky.conf Package library path: /usr/lib64/conky

General:

bad-interpreter commented 6 years ago

I solved: the variable ${apcupsd_status} has a trailing space, so it must be compared with "ONLINE " and "ONBATT ".

su8 commented 6 years ago

What happens when you change the following line:

https://github.com/brndnmtthws/conky/blob/3720e96ca5ae94f838a7fc39fe1f1d559961a3a4/src/apcupsd.cc#L164

to

FILL("STATUS", APCUPSD_STATUS, TRUE);
su8 commented 6 years ago
git clone https://github.com/brndnmtthws/conky
cd conky
mkdir -p build
cd build
cmake ..
make -j4 # 4 cores to run in parallel
src/conky -c ~/conky.conf # <-- your config goes here

Don't forget to change the above line with TRUE.

bad-interpreter commented 6 years ago

Works as expected! No trailing space anymore!

lasers commented 6 years ago

@su8 Mind pushing a fix on new branch to this repository?

su8 commented 6 years ago

@lasers You go ahead and open a PR with this fix :heart:

lasers commented 6 years ago

@su8 What do I describe this? I see it's defined on line 136 saying... FIRST?

EDIT: More accurate to use remove trailing whitespace or remove trailing newline? EDIT: What does if (FIRST) does? I see it check for a space, but the second one?

su8 commented 6 years ago

What does if (FIRST) does? I see it check for a space, but the second one?

It stops on first encountered space character and terminates with '\0' or 0.

More accurate to use remove trailing whitespace or remove trailing newline ?

remove trailing whitespace should be fine.

lasers commented 6 years ago

Closed via https://github.com/brndnmtthws/conky/issues/593. Thank you for the report. Keep them coming.