0

I am wondering if it can be done the way I am imagining it could work.

I tried to find a solution to something that cannot be done within Obsidian or with URL schemes (neither with the Obsidian Advanced URI plugin): make changes e.g. in specific theme settings.
I had more changes but settled on these for now, because they are easy to handle with 2 commands like that.
I have 26 different temporary vaults because Obsidian finds the entirety of my 20000 files too large and exits on me when I open e.g. Zotero or Safari.
Hence I temporarily move my subfolders up one level to figure as bone fide vaults on their own (with their own settings). I access any file (at any Heading level) in these temporary vaults with a single Shortcut.

I have made settings changes to 26 [A-Z] (sub-)vaults in Obsidian. If I wanted to undo those, I would need to write to 26 times 3-4 files in an iOS shortcut, but having the shortcut recursively search and replace data (with A-Shell) would take time on a large vault housing many many folders with their own settings.

I was thinking of just making note of the commit IDs of the commits made and using an iOS shortcut to practically switch between states to apply either set of settings.

Having looked up answers on StackOverflow, I have seen the cherry-pick command as an alternative.
How would I go about using revert and/or cherry-pick to switch between two states (e.g. as in 'day' and 'night' settings)?

Well, the problems:

  • A-Shell Libgit2 doesn't recognize the command revert;
  • NewTerm2 terminal (JB app) can execute git revert <commit-with-hash-ID> (after symlinking the repo/vault), but of course, there are merge conflicts to deal with (one needs changes on particular lines to undo, then it works);
  • Newterm2 doesn't have Siri Shortcut support.
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
zanodor
  • 137
  • 6

2 Answers2

1

Here's a better idea. make use of git stash. You can use git stash to maintain two or more different overlays to config data in your files that you can discard as needed and recall on demand.

If you are making real changes that you want stored in the same files then you will have to use git-add -p for interactive patch style selection of which sections you want added to the commit index. This is a commonly used practice for overriding data in config files for testing that you need to keep recalling and i do it all the time. For example I have log levels that should be set one way for production but for development i constantly want to ratchet them up i dont want to edit the file every time... i just say git stash apply mylog ( having saved them with git stash save mylog)

This is not what git cherry-pick and revert are for. they are really for if you want to commit to the history an undoing of a commit or pull in a commit from another branch to be committed.

UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
  • Yes, that's what I was thinking that other changes to those files will happen over time, then having to deal with individual merge conflicts cause more problems. I am on iPad so I need to look at my possibilities in Libgit2, Git or Working Copy app. Cheers – zanodor May 05 '23 at 17:15
1

UpAndAdam's idea was indeed a good idea. However, git stash is not exactly used for these "workflows," as the temporary "overlays" cannot be discarded. There is no command to do that. I have no intention of making branches off of stashed files, nor do I want manually pick out what should be committed+pushed to the remote.

What I did was run two checkout commands with very easy regular expressions (in NewTerm2, as A-Shell didn't budge with Libgit2):
git checkout -- [A-Z]/.obsidian/appearance.json

git checkout -- [A-Z]/.obsidian/plugins/obsidian-style-settings/data.json

This took care of my "temporary" 52 files, which are now withdrawn from the workspace and I am ready to commit and push my changes.

This whole thing (solution?) is very clunky indeed as it is, especially because I need a one-button solution.

Hereby, I present that solution.

Requirements

Patience. No. There is no patience needed. It'll all be a cinch.

  1. A jailbroken device. JB'ing is pretty straightforward these days, e.g. with the Palera1n ISO (look it up).
  2. Filza JB file manager.
  3. Some expertise or proclivity to learn something about automation, namely iOS Shortcuts.
  4. NewTerm2 terminal: optional.
  5. As this deals with a git repo from the onset, ostensibly you'd need git. If you are using Obsidian sync, you need to figure out a different way with A-Shell, dealing with search and replace in files.

Setup

I'm assuming you've jailbroken your device and installed Filza already.

In order to provide a one-button solution, what we need to do is SSH into our own device's Localhost.

  • In Filza, go into /etc/ssh and open sshd_config in the text editor of Filza.
    Where you see the line # Port 22, type underneath Port 2222 without the hash (the hash stands for comment, now it will be a setting). Save and exit the file.
  • You can also un-hash the line with port 22, but we'll be using port 2222 later.

We can head over to our Shortcuts app. I am assuming you already have some shortcuts to do with Obsidian.
Here I'll just show you how to call these shortcuts silently in SSH.

I am only showing the "difficult" part here, so this can be incorporated into your shortcut e.g. one that runs pull from your remote first, etc.

  • Create a new shortcut:

Search for and rag in "Run script over SSH". For Host, type in 127.0.0.1, port will be 2222, user will be root, and for authentification, we use the Password method, where the default root password is alpine (type it in). Input is left empty.

In the script area, you need to change into a directory (cd) where your repo resides. You can use symbolic links in Filza beforehand. I am using the directory I was accessing git from in NewTerm2. I am using A to Z folders and was making changes to these files in those folders, so I am revoking the changes by checking them out, that is rolling back to what I had before I applied the stash, as per the instructions by Adam.
In my case, the following will cause light mode and different theme settings to be active in all of my subvaults, until (using another Shortcut) I re-apply the stash again to apply the dark mode.

Write in your code in your script area:

cd /var/mobile/<RepoName>
git checkout -- \[A-Z\]/.obsidian/appearance.json
git checkout -- \[A-Z\]/.obsidian/plugins/obsidian-style-settings/data.json

The first time I was running it, I received the error:
fatal: detected dubious ownership in repository at... I followed the on-screen suggestion but nothing happened. I manually edited my config file, I even used the wildcard asterisk; nothing. Same error. Then it occurred to me to run the command from inside the Shortcut, in this very same SSH command, but instead of global I was using system:

cd /var/mobile/<RepoName>
git config --system --add safe.directory /private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/Documents/<RepoName>
  • Note: because the UUID of your Obsidian container/folder changes on each update of the app, it is worthwhile to have and run a shortcut that puts the new UUID into a global variable (of the ToolBox Pro app), and you can use that in all other shortcuts (better than updating your Obsidian PATH in a dozen shortcuts).

Then it was working properly.

The above only caters to a simple use case, yet. You can use multiple stashes and multiple lines in the SSH part of the shortcut, so you can apply various changes unto different vaults with the push of a button.

Obsidian Forum

On the Obsidian Forum, I talk a bit more about the setup: https://forum.obsidian.md/t/ios-macos-siri-shortcut-jb-git-apply-and-switch-between-the-same-multiple-settings-for-all-vaults/59276

zanodor
  • 137
  • 6