Toml: Way to implement "\ " for stored shell commands?

Created on 28 Aug 2019  Â·  4Comments  Â·  Source: toml-lang/toml

I have a shell command stored in a value that normally requires me to escape out spaces using '\ ', i.e. a backslash followed by a space. This is for a .toml configuration file from the gebaard project (it's a touchpad multi-touch gesture parser*): https://github.com/Coffee2CodeNL/gebaar-libinput

Snippit from the .toml file:

[commands.swipe.three]
left = "qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\ One\ Desktop\ to\ the\ right"

This is meant to execute the qdbus method -- a kde/kwin method for switching virtual desktops -- on a left swipe. Normally for the command to be executed in a shell, the entire command either needs to be quoted or the spaces escaped with "\ ". Unfortunately, it appears '\ ' is an illegal escape character, as when I try running the requisite program that parses the above .toml file, I am returned with this error:
terminate called after throwing an instance of 'cpptoml::parse_exception' what(): Invalid escape sequence at line 8 [1] 12435 abort (core dumped) gebaard

So my question would be, since the value to be parsed from the .toml file is supposed to be a shell command that requires spaces to be escaped, is there a way for me to properly write this in a/the .toml file?

question

Most helpful comment

@keiichiiownsu12: Even better, as long as your command doesn't contain any single quotes (apostrophes), you can write it as a literal string – those are surrounded by single quotes and don't require (or allow) any escaping:

left = 'qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\ One\ Desktop\ to\ the\ right'

Should some of your commands contain single quotes, you could still write them as triple-quoted (= multi-line) literal strings:

left = '''qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\ One\ Desktop\ to\ the\ right'''

All 4 comments

You can use \\.

left = "qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\\ One\\ Desktop\\ to\\ the\\ right"

I. . .cannot believe how retarded I am XD

Thank you for the quick clarification!

@keiichiiownsu12: Even better, as long as your command doesn't contain any single quotes (apostrophes), you can write it as a literal string – those are surrounded by single quotes and don't require (or allow) any escaping:

left = 'qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\ One\ Desktop\ to\ the\ right'

Should some of your commands contain single quotes, you could still write them as triple-quoted (= multi-line) literal strings:

left = '''qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut Switch\ One\ Desktop\ to\ the\ right'''

What about this?

left = "qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut 'Switch One Desktop to the right' "

Should work I would say, and it's cleaner than escaping the spaces in between.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clarfonthey picture clarfonthey  Â·  4Comments

jdfergason picture jdfergason  Â·  4Comments

ChristianSi picture ChristianSi  Â·  3Comments

genericptr picture genericptr  Â·  4Comments

uvtc picture uvtc  Â·  3Comments