First of all, clone your github repo to place where you want to keep it. I would assume here that your repo name is logseq and you will keep it in your documents folder
cd ~/Documents && git clone https://github.com/YourGithubUsername/logseq.git
Install fswatch with homebrew, if you’re using this package manager. If not, install it first https://brew.sh/ , or compile fswatch yourself, there is INSTALL file with instruction in their repo.
Create folder log
in your user folder mkdir ~/log
Create file com.thatguy.logseqfswatch.plist
and place it in ~/Library/LaunchAgents/
. Content of the file:
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.thatguy.logseqfswatch</string>
<key>Program</key>
<string>~/Documents/logseq/logseq-fswatch.sh</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>~/log/logseqfswatch.log</string>
<key>StandardErrorPath</key>
<string>~/log/logseqfswatch.log</string>
</dict>
</plist>
Create file logseq-fswatch.sh
and place it in ~/Documents/logseq/logseq-fswatch.sh
. Content of the file:
#!/bin/bash
/usr/local/bin/fswatch -0 ~/Documents/logseq -l 10 -e "\\.git.*" | xargs -0 -n 1 -I{} sh -c 'cd ~/Documents/logseq && git add .; git commit -m "auto sync"; git push;'
It will add, commit and push changes 10 seconds after it detect it. If you want to push immediately then remove -l 10
.
Make this file executable chmod a+x ~/Documents/logseq/logseq-fswatch.sh
Run these commands
launchctl load ~/Library/LaunchAgents/com.thatguy.logseqfswatch.plist
launchctl start com.thatguy.logseqfswatch.plist
And right away run this tail /var/log/system.log
and look if there are no errors regarding your com.thatguy.logseqfswatch
service.
Thats it for pushing your local changes to github repo. Now for pulling changes:
Create file com.thatguy.logseqautopull.plist
and place it in ~/Library/LaunchAgents/
. Content of the file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.thatguy.logseqautopull</string>
<key>ProgramArguments</key>
<array>
<string>git</string>
<string>-C</string>
<string>~/Documents/logseq/</string>
<string>pull</string>
</array>
<key>StandardErrorPath</key>
<string>~/log/logseqautopull.log</string>
<key>StandardOutPath</key>
<string>~/log/logseqautopull.log</string>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
It will pull changes from github every 60 seconds, you can change this line <integer>60</integer>
if you want different interval.
Run these commands
launchctl load ~/Library/LaunchAgents/com.thatguy.logseqautopull.plist
launchctl start com.thatguy.logseqautopull.plist
If you see that something didn’t sync, you can look for errors in logs in ~/log
folder.
That’s all, at least it was for me
There are minor problems with Logseq when it comes to working on multiple devices, you might see in your mobile devices that it want you to decide if you want to keep your local changes or update it with changes from github. AFAIK they are working on making it more smooth.