Skip to content

Sync Obsidian Android using Termux and Git (SSH) ๐Ÿ“‘

Notifications You must be signed in to change notification settings

GiGiDKR/OhMyObsidian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

OhMyObsidian ๐Ÿ“‘

Easily sync your Obsidian vaults on Android using Git (SSH) + Termux. Automation and shortcuts using Tasker which works whether a vault is open or not to synchronize it. 1

To prevent conflicts, add the following lines to your .gitignore file in all your vaults that you'll be syncing using Git. If you notice a plugin has a file which is often in conflict, you'll want to add that as well (remember to un-track it with git rm --cached <file>):

/.obsidian/workspace.json
/.obsidian/workspace-mobile.json
/.obsidian/plugins/obsidian-git/data.json
/conflict-files-obsidian-git.md

To stop conflicts from happening with your note files, you can create a .gitattributes file in the root of your vaults with the following content. It will basically always accept both changes for .md files.

*.md merge=union

Termux setup

  1. Install F-Droid or Obtainium
  2. Install Termux from F-Droid or Obtainium

Obsidian sync setup

Important

A full installation script is available with optional use of gum to get a cleaner and beautiful scripting interface. To run it enter:

curl -o $HOME/install.sh https://raw.githubusercontent.com/GiGiDKR/OhMyObsidian/main/install.sh && chmod +x $HOME/install.sh && $HOME/install.sh

๐ŸŽ€ Add --gum or -g at the end of the command to use the gum interface

Manual installation

  • Optional : To install / update packages you can select a particular repository to increase the speed of download : termux-change-repo
  1. Run the following commands :
termux-setup-storage
pkg update && pkg upgrade -y && pkg install -y git openssh termux-api
mkdir -p /storage/emulated/0/Documents/Repository $HOME/OhMyObsidian
git clone https://github.com/GiGiDKR/OhMyObsidian.git ~/storage/shared/Documents/Repository/OhMyObsidian

Warning

Be aware that the next step will set safe.directory to '*'

  1. Run the setup script :
cp "/storage/emulated/0/Documents/Repository/OhMyObsidian/setup" ~/OhMyObsidian/ && chmod +x "$HOME/OhMyObsidian/setup" && source "$HOME/OhMyObsidian/setup"
  1. The above command copied an SSH public key to your clipboard (or was displayed to the screen), paste this into your Git host's SSH key authentication setting (eg Github). If you want to copy the SSH key again, run the setup script again.

  2. In Termux, you should now be in the Obsidian directory (verify with pwd) where you can clone your Obsidian vaults. Try not to put any special characters in your vault name.

Note

  • Sync all the vaults in Obsidian folder : sync
  • Get the status of the vault sync : status
  • Open Obsidian from Termux : open

Tip

By default Git does not remember your credentials but it is possible to change this with a Credential Helper :

Remember your credentials during a session :

git config --global credential.helper cache

Remember during 1 hour :

git config --global credential.helper 'cache --timeout=3600'

Remember permanently (less secure) :

git config --global credential.helper store

Tasker Setup 1

Here's an image of what it looks like, once complete with shortcuts to some optional utility functions. Each vault will have it's own icon. This allows syncing to be more efficient as without it, all vaults will sync each time in a specific order. Instead of just the vault that you open being synced immediately. If you only use one vault or don't mind the inefficiency of waiting for the vault that you just opened to be updated, then you can use the default Obsidian app icon. Also, all vaults are synced once a day (defaults to 4am).

  1. Install Tasker from the Play Store.
  2. Install F-Droid.
  3. Install Termux:Tasker and Termux:API from F-Droid or install from Obtainium : Termux:Tasker / Termux:API)
  4. Enable the Termux permission in the Android settings of the Tasker app.
  5. Open the Obsidian app and add your vaults from the Obsidian folder.
  6. If you're using the Obsidian Git plugin, you should disable it for this device. You can do this in the plugin settings.
  7. Import the "Tasker project" into Tasker. Once you import it, I recommend you rearrange the tasks based on this image for simplicity (to rearrange tasks, hold on a task, then drag). You can import the project in 2 ways. You can use this TaskerNet link, or you can import (image) the .xml file from this repository. Once it's imported, there will be some prompts, I think one for giving Tasker "Usage Access" and one to enable all profiles. Accept all.
  8. Vault launch icons - There are 2 example tasks (Vault1 and Vault2). Rename the task to the name of your vault (you can name it anything). Then in the task, you'll see a "Variable Set" action, change the value to the name of the folder which contains the repository for that vault.
  9. Give Termux the "Display over other apps" permission.
  10. Add the Vault launch icons as Tasker widgets (use the widget type that allows you to add them to folders) to the home screen. Also, add the 3 helper tasks as widgets (as needed):
    1. Sync Vaults - syncs all vaults
    2. Vaults Status - outputs the git fetch && git status of each vault
    3. Sync Log - outputs the sync log.

All vaults will sync at 4am every day using a Tasker profile.

Notes

  • You should get a notification if a sync fails. This requires AutoNotification from the PlayStore. To disable this, disable the Sync Error Notification profile.
  • The individual vault icons to open specific vaults can be a bit slow. I've tried different ways to open a vault. Faster ways had one of two problems. Either it would open the vault correctly, but then if you left the app, it would not appear in the recents list. Or, it would load the app, load the last vault used, then load the vault you wanted which ends up being slower then the current method. You can find almost all the methods I tried in the Open Vault task (they are disabled).
  • If you prefer, you can have a popup menu (a scene or list dialog for example), to combine all the actions or vaults into one icon on your home screen.
  • If this repository has new commits that you want, running the setup command should pull them down. After which, you may be prompted to run a command to update the setup script itself, if it was updated.

Version history

  • 1.0 : Initial version (adapted from Obsidian-Android-Sync)
  • 1.0.1 : Added zsh-friendly configuration
  • 1.0.2 : French translation
  • 1.0.3 : Added a automated script
  • 1.1 : In development

Footnotes

  1. Do not use for now : adaptation to come in v1.1 โ†ฉ โ†ฉ2

About

Sync Obsidian Android using Termux and Git (SSH) ๐Ÿ“‘

Resources

Stars

Watchers

Forks

Languages