I3status-rust: Escaping characters in custom commands

Created on 7 Dec 2019  路  7Comments  路  Source: greshake/i3status-rust

As my hardware doesn't appear to be supported by lm_sensors (cf. #469), I tried writing the following custom block:

[block]]
block = "custom"
command = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf("%.1f\n",$1/1000)}'"

However, this produces an error:

Configuration error: failed to parse TOML from file. Cause: unexpected character found: `%` at line 52

I assume this is user error, but I haven't yet found anything to explain how to escape a '%' character in a TOML string. Not sure if this is an ordinary TOML issue or something specific to i3status-rust.

question

All 7 comments

What about replacing the double quotes in the printf with single quotes? Or escaping them instead?
Either way at least gets rid of the TOML parsing issue for me but you will need to see if it still runs your command properly.

Thanks for the suggestions! Neither of these seems to run the command correctly (I appended 2>&1 to the command, so that i3status-rust would show me the errors it got when it ran the command).
Single quotes:

awk: cmd. line:1: {printf('%.1f
awk: cmd. line:1:         ^ invalid char ''' in expression
awk: cmd. line:1: {printf('%.1f
awk: cmd. line:1:         ^ syntax error "

Escaped double quotes (using \"):

awk: cmd. line:1: {printf(\"%.1f
awk: cmd. line:1:         ^ unterminated string
awk: cmd. line:1: {printf(\"%.1f
awk: cmd. line:1:         ^ syntax error 

Just to make sure the issue isn't with i3status-rs or the toml crate we use, I checked the latest version (we use an older version), however I couldn't find any mention of bugfixes related to this. Checking with http://toml-online-parser.ovonick.com/ (some random syntax checker I found), it seems like this issue is purely to do with TOML.

This works for me:

[[block]]
block = "custom"
command = ''' cat /sys/class/thermal/thermal_zone0/temp | awk '{printf("%.1f\n",$1/1000)}' '''

Output:

{"version": 1, "click_events": true}
[[{"background":"#000000","color":"#a9a9a9","full_text":"| ","markup":"pango","separator":false,"separator_block_width":0},{"background":"#000000","color":"#93a1a1","full_text":" 27.8 ","markup":"pango","name":"ec0bf73aebe811e7bdf7f9","separator":false,"separator_block_width":0}],

Yes, that works, thanks! I had tried using ''', but I didn't have the space separating them from the contents of the string, so it didn't work.

Do you think it would be worth putting a sentence in the docs for the custom block suggesting ''' when the command has wacky characters in it?

Maybe could be used as an example block for the Custom block?

Added it as an example in the docs so hopefully it can help the next person who comes across this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dieterbe picture Dieterbe  路  4Comments

l4l picture l4l  路  6Comments

svenstaro picture svenstaro  路  4Comments

YodaEmbedding picture YodaEmbedding  路  4Comments

oschoudhury picture oschoudhury  路  6Comments