Install Termux and Termux Widget
From Github Termux ,[^1] Github Termux Widget [^2] download the APKs and install them. You can use F-Droid as well.
Give Termux access to your storage using the following command :[^3]
termux-setup-storageSetup Git and Github for Manipulating Repositories
Use the following commands to setup git and github via HTTPS :
pkg update && pkg upgradepkg install gitpkg install ghYou can use SSH as well
Login to your Github account :
gh auth loginUpdate the git configs :
git config --global user.name "name"git config --global user.email "email"Now you should clone your repository, try to use the following commands :
git status
git pull
git commit
git pushIf you are on Android 12, you’ll get an error with the command required to add the repository to a security list or something like that. Do it, and these commands should work.
Setup the Sync Script Shortcut
Create a directory for the shortcuts :[^4]
mkdir -p /data/data/com.termux/files/home/.shortcuts
chmod 700 -R /data/data/com.termux/files/home/.shortcuts
mkdir -p /data/data/com.termux/files/home/.shortcuts/tasks
chmod 700 -R /data/data/com.termux/files/home/.shortcuts/tasksCreate the sync script :
nano /data/data/com.termux/files/home/.shortcuts/tasks/sync_script.shAdd the following script :[^5]
#!/bin/bash
cd storage/shared/LifeWiki
git pull && git add -A && git commit -a -m "android vault backup: `date +'%Y-%m-%d %H-%M-%S'`" && git pullCreate the widget and add it to your home screen. That’s it, you just need to launch it to sync your Obsidian vault. It means you need to launch it before and after editing notes. If you putted your script inside ~/.shortcuts it will launch in the foreground, and if it was inside ~/.shortcuts/tasks then it will launch in the background. I recommend using as a widget the one that execute the code in the foreground and keep the other one for the Cron job.
Setting up an Automatic Execution of the Script
If you want to automatically sync your vault every hour, for instance, you can do it using a Cron job. [^6] [^7] [^8]
First, you need to install Cron :
pkg install cronie termux-servicesThen, you’ll restart Termux then run the following :
sv-enable crond
crontab -e Finally, you’ll end up with the crontab -e command in the nano text editor. Add the following :
* */1 * * * bash ~/.shortcuts/tasks/sync_script.shYou can find information about Cron job easily on the internet.[^9]