obsidian-shellcommands
obsidian-shellcommands copied to clipboard
Wrap shell command output
Quote from me in: https://github.com/Taitava/obsidian-shellcommands/discussions/244#discussioncomment-3211841
I think this is what you meant. Make it possible to configure text snippets that could be used as wrappers for output. E.g. the following could be an output wrapper text:
``` {{output}} ```
If the executed shell command is e.g.
ls
(lists files and directories), then an example resulting output could be:``` MyFolder MyNote.md MyOtherNote.md ```
The wrapper texts could be defined in settings, and multiple shell commands could use the same wrapper if wanted - no need to redefine the same wrapper for every shell command. The wrapper could be used regardless of what output channel is used: when outputting into file, into clipboard or into a notification balloon or whatever.
TODO
- [x] UI: Creating, deleting and modifying OutputWrappers.
- [x] UI: Assigning OutputWrappers to shell commands.
- [x] Use OutputWrappers in the output handling process.
- [x] Create an {{output}} variable.
- [x] Parse variables when using OutputWrappers.
- [x] Consider an alternative way for parsing variables.
- [x] Make test cases.
- [x] Write documentation.
It's implemented now, but I still want to consider doing the variable parsing in output wrappers a bit differently. Currently, variables in output wrapper texts are parsed after executing a shell command. This has the following points:
- Variables in output wrappers might have different values than what the same variables would have in the actual shell command. E.g.
{{date:HH:mm:ss}}
might have different seconds, if the shell command execution takes long. - If the variables used in output wrappers have problems that prevent parsing them, the problems are only noticed after the shell command is executed, and there's no possibility to cancel the execution. The output will then be used as-is, without any wrapping.
-
{{event_*}}
variables cannot be used in output wrappers (well, could, but implementing them here would require some tweaking).
I want to try to come up with an alternative solution that could parse variables in output wrappers before executing a shell command. That would solve the abovementioned three problems. It might be hard to do, though. That being said, even this current implementation is ok, if an improvement is too hard to make.
I won't release this feature until I've inpsected the alternative solution.
I was able to implement the alternative solution.
Only tests need to be made, then it's ready.
Tests are done.
I just noticed that any variables used in output wrappers are escaped (except {{output}}
), although they should not be. Output wrapper texts are not passed to shells, so escaping special characters in them should not be done, as the ecaping won't disappear in the end.
- [x] Alter the variable parsing process so that it allows flagging if certain content doesn't need escaping.
Released now.