Explore the plugin…
I think we’ve already established that your original request of commit&push is best done through throught a create backup command from the Git plugin, or either of the very similar variants:
So I’m not going to say so much more about that, other than that since the plugin offers these commands some thought and consideration on how to perform this operation has been taken before including it into the plugin.
Using QuickAdd
- Open Settings > QuickAdd
- Close to Add choice button, select Macro, add a name like “gitDouble”, and hit the Add choice button
- Click the lightning icon
- Click the gear icon, and then the plus icon to create a new macro (with the same (or another name)). You should now get an image resembling the following:
- Find the commands you want to execute in the Obsidian command line, and hit the Add button. I’ve done that for two “random” git commands of opening the history and the diff view
- Close off the dialogs
- Go to Settings > Hotkey, search for your name, and assign a hotkey to it
Using Templater
If you instead of relying on the “internal” git plugin, and rather would want to use external/shell commands, instead of writing a javascript variant to execute those in child processes, I would rather use the User system command functions found at the bottom of Settings > Templater, and define the commands I would like to do in sequence there.
This would allow for a slightly better handling of the commands, with some error handling and encapsulation provided by the plugin so that your commands should be safer to run from within Obsidian.
Using javascript
If neither of the above are appropriate for you, and you would need/want to use javascript the first choice would be related to how to execute that javascript. Just a few options for that could be:
- Either of the dedicated javascript plugins like RunJS or CustomJS or JS Engine or Javascript Init or … Plenty of options exists
- Reuse one of your already installed plugins, like Templater, QuickAdd or User Plugins (which I’ve got installed due to other personal preferences which that plugin helps me with)
Further since we’re talking about Obsidian commands, I would use app.commands.executeCommandById
, after locating the command id:
- See Is using `app.commands.executeCommandById` officially supported?
- See Obsidian commands, hotkeys and duplicate hotkey assignments
And the resulting javascript snippet would most likely look something like the following untested code:
await app.commands.executeCommandById("obsidian-git:open-history-view")
await app.commands.executeCommandById("obsidian-git:open-diff-view")
Or something similar…
I’m not going to do the full javascript explanation for that last one, as I consider the other options as better suited in most cases, but this post should now show some of the vaste opportunities you’ve got for doing such a task as executing two Obsidian commands “at once”. Hope either of these options suits your needs, or gives you enough information to move forward.