Option to use metadata list item as tokens to command #337
Replies: 1 comment 1 reply
-
Hi, thank you for your message! 🙂
Hmm, I think the documentation page needs some updating. The general idea of escaping is good, and works as a safe default way on how to do things. It's good that you have thought about alternative ways. However, in your situation I think it's perfectly fine to disable escaping. I think these could be rules of thumb:
The documentation page assumes that In your use-case, you know that whatever you put to your If your shell command would be something like But now let's have a look at your suggestion. 🙂
This has actually been on my mind for way too long, but I still haven't made up my mind on the syntax, so that's why I haven't implemented it yet. Currently, the In your case, it could be: cd {{yaml_value:production-links.0.directory}} && {{yaml_value:production-links.0.open-command}}->{{ }} Note that there are no quotes We can continue this join discussion in #147. 🙂
Sorry, I didn't understand this. |
Beta Was this translation helpful? Give feedback.
-
I have some front matter that specifies a command to be executed to view/edit/cd to a various project directories.
And I have the following shell commands defined:
cd {{yaml_value:production-links.0.directory}} && {{yaml_value:production-links.0.open-command}}
cd {{yaml_value:production-links.1.directory}} && {{yaml_value:production-links.1.open-command}}
cd {{yaml_value:production-links.1.directory}} && {{yaml_value:production-links.2.open-command}}
etc.
This works for the first case, but for the second and third I have to disable escaping variables fpr the command to work:
cd {{yaml_value:production-links.1.directory}} && {{!yaml_value:production-links.1.open-command}}
cd {{yaml_value:production-links.1.directory}} && {{!yaml_value:production-links.2.open-command}}
The recommendation NOT to disable escaping (https://publish.obsidian.md/shellcommands/Variables/Escaping+special+characters+in+variable+values), makes me think of alternate ways to doing this.
One option to add separate metadata for each argument:
cd {{yaml_value:production-links.0.directory}} && {{yaml_value:production-links.0.open-command}} {{yaml_value:production-links.0.open-arguments}}
This works in the simple case (i.e., single argument), but that gets out of control as the number of arguments might vary and increase and need to be anticipated.
Another option would be if Shell Command has an option that can "expand" a list argument with a separator. For example
{{yaml_value:production-links.0.open-command:join(" ")}}
Then the YAML could be:
And the shell command is also a lot simpler:
cd {{yaml_value:production-links.0.directory}} && {{yaml_value:production-links.0.open-command:join(" ")}}
Another syntax could be like the disable token, e.g.
{{@yaml_value:production-links.0.open-command}}
Beta Was this translation helpful? Give feedback.
All reactions