This is a way to write and share notes for yourself between multiple devices, without signing up for locked-in cloud services, using only future-proof formats and open tools!
This is built on Android and Obsidian, which are only semi-open, but because it's built on syncing with git and markdown if you need to replace the platform you can, because markdown and git work everywhere and will continue to work everywhere for a long time.
(Android) phone:
-
(Optional) Install Markor which is a more fully-featured markdown editor
-
- pay attention to all the setup steps, especially "Draw over other apps"
- add the Widget to your homescreen
-
- enable Draw Over Other Apps here (TODO: this is intentionally buried on Android 14+, explain where to find it)
pkg install termux-api
to give Termux access to it
-
pkg install jq openssh git
-
Install scripts below to
~/.shortcuts/sync-notes
and~/.local/bin/android_ssh_askpass
.Remember to
chmod +x
both of them. -
Make an ssh key
ssh-keygen -t ed25519
- (optional but STRONGLY recommended): set a passphrase on the key
-
cat ~/.ssh/id_ed25519.pub
+ copy the public key and send it to yourself
- Install the key on whatever git server you're using
-
termux-setup-storage
+ make sure to grant Termux access to the path containing your diary -
Set up a git repo:
cd storage/shared git clone git+ssh://yhour-server/your-path/to-diary-repo.git Diary
OR if you're starting from scratch:
Open Diary at least once so that it creates its default folder, then sync that folder to a git server.
cd storage/shared/Diary git init git remote add origin git+ssh://yhour-server/your-path/to-diary-repo.git git push -u origin
but it's probably easier to init the repo from anywhere that's not your phone -- do it from your desktop, with Obsidian and GitHub/Lab/BitBucket/Forgejo/your own server with ssh access handy.
-
If you set a passphrase, make it remain unlocked in RAM
(or you'll be re-unlocking it every 15 minutes)
sv enable ssh-agent
- Install Termux:Boot
- make sure to follow the setup steps, especially disabling battery optimizations for both Termux and Termux:Boot
- Put this in
~/.termux/boot/start-services
.
```sh #!/data/data/com.termux/files/usr/bin/sh termux-wake-lock . $PREFIX/etc/profile ``` - Run `termux-wake-lock` at least once and accept the "Disable battery optimizations" prompt that comes up (**TODO:** why does this have to be done twice? did I just not do it right the first time?) - `termux-wake-lock` is, **I think**, equivalent to "disable battery optimizations". It doesn't actually mean that your device will be forced to chew through power, especially not with just `ssh-agent` running which is asleep until something calls on it. - Reboot.
-
(optional) Tune git to better defaults
(these are my preferences, read about them first)
git config --global advice.mergeConflict false git config --global merge.conflictStyle diff3 git config --global push.default current git config --global push.autosetupremote true
-
Test:
- run
~/.shortcuts/sync-notes
from Termux - run 'sync-notes' from the Termux:Widget on your Homescreen
- run
-
If works, schedule it:
termux-job-scheduler -s ~/.shortcuts/sync-notes --period-ms 900000 --persisted true
Now your notes should also automatically attempt a sync every 15 minutes.
If the sync fails due to network problems or a conflict, your notes will be left untouched but you will get a notification about it, and you should cd storage/shared/Diary
and attempt git pull
to investigate the situation. If you have conflicts you will have to fix them using Diary or Markor, or maybe vi if you're comfortable with vi, and then recommit and push.
Desktop:
- these are the only markdown editors that currently exist that understand folders.
- install Obsidian-Git and configure it to
- commit-and-sync every 15 minutes
- commit-and-sync on opening
- there are lot of plugins for obsidian that help; but I don't want to become reliant on them
Server:
- Git
- (Optional) GitHub/Gitea/Gitlab/Forgejo (to get a web-based diary) 2. TODO: link to a guide to setup mkdocs
-
Edit files on phone
-
Wait for sync to happen in the background.
- If it errors you will get the error as a notification, and also in
logcat
- If it errors you will get the error as a notification, and also in
-
Run
sync-notes
manually if you don't want to wait; it will pop to the foreground.- If it errors, you will see the error message on screen, and also in
logcat
- If it errors, you will see the error message on screen, and also in
-
It will prompt you if it needs the key (on first boot, or if it's been idle long enough that Android has killed the background termux session)
- Obsidian cloud
- PuppyGit (see demo)
- the various orgmode apps in fdroid? I haven't explored these too much, but I think some of them do syncing?
- EverNote, Notion
View log:
adb logcat | grep sync_notes
- Android is very kill-happy. Termux:Boot doesn't seem to be doing it's job of providing
ssh-agent
, and therefore the unlock prompt comes up over and over again.- Workaround: launching Termux and just leaving it in the background keeps
ssh-agent
alive. - To investigate: does using
termux-wake-lock
as recommended prevent this? Doestermux-wake-lock
have other negative consequences? - To investigate: instead of using the Android job scheduler, use a Termux:Widget ~/.shortcuts/tasks instead. Can that stay up in the background without being killed?
- Workaround: launching Termux and just leaving it in the background keeps