Taitava / obsidian-shellcommands

Execute system commands via hotkeys or command palette in Obsidian (https://obsidian.md). Some automated events are also supported, and execution via URI links.
GNU General Public License v3.0
336 stars 11 forks source link

adding a special case, where an object, which is an array of strings … #416

Open jvsteiner opened 2 weeks ago

jvsteiner commented 2 weeks ago

…can be accessed as a single variable, and the strings will be returned as space joined string.

This addresses https://github.com/Taitava/obsidian-shellcommands/discussions/415

It is a change to the code that fetches variables from YAML frontmatter. In my use case, I would like to use a single YAML property, which contains an ordered list of strings to generate multiple shell parameters:

my-property:
  - foo
  - bar
  - baz

In the current code, the function chain returns a single string when successful, and a []string of errors when it fails. To accomplish this case, I wait until the last possible moment: right before "Freak out." and make a final check if the object is, in fact, an array of all strings. If it is, I concatenate them with a space separator, and return them as a single string.

There is a small problem that the space separators are escaped, causing the shell arguments to be interpreted as a single, long argument, but by using the {{!property_value}} notation, it can still be worked around. This has the undesirable side effect/corner case that, if individual members of the list contain spaces, they must manually escaped.