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?
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.
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:
Should some of your commands contain single quotes, you could still write them as triple-quoted (= multi-line) literal strings: