Import / Export Commands #151
Replies: 5 comments 11 replies
-
Is the idea behind this to let this plugin serve a similar role as templater, where more advanced users could create code that others could easily use, and build out a sort of automation ecosystem? She asks, knowing remarkably little about shell scripting but being willing to learn... |
Beta Was this translation helpful? Give feedback.
-
Thank you for the suggestion! 🙂It's nice to see people thinking about features that have crossed my mind. For me, this has been a maybe sometime in the future thing, which I did not want to plan too much ahead before seeing a clear need for it. Now that you suggested it, I can see that maybe it is beneficial. In addition to sharing shell commands with other people, I can see myself using it to copy them between my different vaults. Different vaults use partly different shell commands, so I don't want to just copy (or sync) the whole settings file between my vaults. But certain shell commands (mostly Git related) are something I use in all my vaults. I'll divide my so-far thoughts about this feature under the following headings: ConcernsSafetyShell commands are dangerous. That's a fact that is obvious to all of us. Nobody should copy and paste these from the internet without knowing every detail of the shell command that they just copied from somewhere. The recent release of I like to think that people in the Obsidian community are truthful and kind to each other (which they usually are!), but there's always the risk that someone publishes badly behaving shell commands, either intentionally or by accident. The plugin cannot safeguard users from importing dangerous shell commands. No program can determine with 100% accuracy if a shell command is safe or not. But what the plugin can do, is to try to show as clearly as possible, what features a shell command will use, if it is imported. E.g. if the shell command enables some events, display a warning for each enabled event. Warn also if the shell command's output channel is set to write into a file. These warnings would be shown immediately after a user pastes a shell command into an importing text field, before the shell command is saved and taken into use. Still the shell command itself can be dangerous. For this, there needs to be a checkbox like I confirm that I have thoroughly inspected this shell command, and I know exactly what it does. How global settings affect individual shell commandsAnother concern is the fact that global settings that affect the execution of shell commands, should be dealt with somehow. E.g. Working directory setting and Default shell settings. When you export a single shell command, you need to take into account that it relies on these global settings, too. I have not come up with a solution for this yet. Practical design decisionsThe exported shell commands will be presented in a long textual format, that will contain a lot of features. It may happen that a user does not notice some dangerous details in the shell command. If you open up a "51": {
"platform_specific_commands": {
"default": "echo \"SOMETEXT\""
},
"shells": {},
"alias": "Event: After Obsidian starts",
"confirm_execution": false,
"ignore_error_codes": [],
"output_channels": {
"stdout": "current-file-caret",
"stderr": "notification"
},
"output_channel_order": "stdout-first",
"events": {
"on-layout-ready": {
"enabled": true
},
"every-n-seconds": {
"enabled": true,
"seconds": 60
}
},
"command_palette_availability": "enabled"
} This is just a single shell command stored in the settings file. This example is actually quite dummy, it inserts the text SOMETEXT into current file (caret position) every 60 seconds and every time a users switches between panes. These things might not be clear to a user who is not familiar with this format. And I guess not many users of this plugin actually open up the settings file to see how their shell commands look like there. Export will use YAML instead of JSONI can't make the above example 100% easy to read, but I can at least improve the readability a bit. The settings file is stored in JSON format, which is good enough for data written and read by computers, but not good to be read by humans. So I've decided to use YAML for exporting. Here's the same example converted to YAML: 51:
platform_specific_commands:
default": "echo \"SOMETEXT\""
shells: []
alias: "Event: After Obsidian starts"
confirm_execution: false
ignore_error_codes: []
output_channels:
stdout: current-file-caret
stderr: notification
output_channel_order: stdout-first
events:
on-layout-ready:
enabled: true
every-n-seconds:
enabled: true
seconds: 60
command_palette_availability: enabled ID should be random instead of sequentialCurrently, shell command ids are just sequential numbers starting from An exported shell command needs to have an id present, because I want to be able to notice a situation where a user tries to import a shell command they already have in their vault. In this case, SC can ask Do you really want to import this shell command again? The user could select to import a duplicate shell command, or to replace the old shell command. The latter makes sense if the user has edited the command in one vault, and is now bringing the updated command to another vault. Support commenting each line (added 2022-08-18)YAML supports adding comments by using the 60:
platform_specific_commands:
default": "/bin/bash my-script.sh {{file_name}}"
...
events:
on-layout-ready:
enabled: true # This command needs to execute every time the user switches the active pane because it needs to reflect the changed current file name in a file that it writes to.
every-n-seconds: # This command also needs to execute every minute because blah blah blah...
enabled: true
seconds: 60 # I decided to use 60 seconds as the value because it's well balanced between not running the heavy process too often, and not making the user to wait for too long between cycles.
... These comments could be shown to the user at the time of importing, but they would disappear after importing - they would not be saved in the actual Future-proofSC version should be present in the exportThe shell command format changes every now and then. New fields get added, and old fields get modified or sometimes even removed. The exports need to have version numbers available, so that the import process knows if it supports the shell command or not. An old version of SC cannot read shell commands exported from a newer SC. A new version of SC can be able to migrate shell commands exported in an old format - to a certain extent. All these migrations require some migration code to be in place in the plugin. In the future, there might be a situation where some migration code is really ancient, and only rarely needed in practise, if ever. There might come a time when it's better for the sake of code cleanness to remove some age-old migration code. This can happen when a major version of SC changes, e.g. from Implement this feature when the plugin is matureTo avoid a large amount of migration code needed to be preserved, I think it's best to first develop this plugin into maturity, i.e. to the version Migration code is in place already now, as old settings files do exist. But it has a difference: When users upgrade their plugins, their settings file gets migrated to a new format. But if there are exported shell commands out in the wild world, nothing will upgrade their format in the place where they reside. That's why I'd like the first exported shell commands to be born in a form that is mature enough to be able to live for years to come. Any feedback on these thoughs? 🙂 |
Beta Was this translation helpful? Give feedback.
-
A place for sharing shell commands?With the ability to export shell commands in text format, it's obvious that shell commands could be shared wherever users collaborate with each other: Obsidian forum, Discord, GitHub, Obsidian Publish sites, blogs etc. Those are all good platforms, but I became to think that would there be any benefit from some kind of centralized library for shell commands that would serve in addition to those? I'm thinking of some kind of a website where users could login (maybe with GitHub login) and submit their exported shell commands under different categories. It's just a far-future idea, and nothing certain. 🙂 |
Beta Was this translation helpful? Give feedback.
-
Yes, me too. Windows: $listfile = './Obsidian Shell commands list win.md'
Write-Output '```json' > $listfile
Get-Content "{{vault_path}}\.obsidian\plugins\obsidian-shellcommands\data.json" | jq >> $listfile
Write-Output '```' >> $listfile Mac: listfile='./Obsidian Shell commands list mac.md'
echo '```json' > "$listfile"
cat "{{!vault_path}}/.obsidian/plugins/obsidian-shellcommands/data.json" | jq >> "$listfile"
echo '```' >> "$listfile" |
Beta Was this translation helpful? Give feedback.
-
Examples of other plugins with import/export functionality@chrisgrieser I'm coming back to this old comment of yours:
Can you provide me some examples of what plugins have this feature, please? 🙂 I haven't used too many plugins myself. I'd like to have a look on what kind of data format(s) they use (e.g. YAML, JSON, or something else). |
Beta Was this translation helpful? Give feedback.
-
Some plugins do allow you to import or export settings. This would be incredibly useful for this plugin, too, so the more shell-adept member of the community can write small scripts other's can use.
One straightforward example for that could be using shell commands as a replacement for the Pandoc plugin, many writers are dearly missing.
Beta Was this translation helpful? Give feedback.
All reactions