This is the second part of three part post series. Be sure to checkout part-1 before continuing here.
In this post I am going to create a script which does only one thing: Take all uncommitted changes and pushes them to remote repository. In next part of the series we will create a systemd service and systemd timer to timely execute this script.
There are three parts to achieve successful state.
- A script which pushes the latest changes to remote
- Create a systemd
servicewhich executes the script
- Create a systemd
timerwhich schedules when to run the script
This part i am going to cover first point which is, to create a script which takes all changes from your obsidian vault and push to remote repository. Three steps for this:
git addchanged files
git commitwith some default message
git pushto remote git repository
The next and the final part of series will cover creating systemd
The setup and the script below executes a local script which does a git add, commit and push to git remote obsidian valut.
1cd ~ 2mkdir -p .obsidian
1bash -c "cat >~/.obsidian/obsidian-sync.sh" <<EOF 2#!/bin/bash 3obsidian_path=\$1 4echo "changing to obsidian vault located at \$obsidian_path" 5pushd \$obsidian_path > /dev/null 6git add . 7git commit -m "auto push by obsidian-sync.service" 8git push 9if [ \$? -eq 0 ]; then 10 echo "successfully push at `date`" 11else 12 echo "failed push at `date`" 13fi 14popd > /dev/null 15EOF
1changing to obsidian value located at /home/munmeh/Documents/gitrepo/obsidian-personal-vault/ 2On branch main 3Your branch is up to date with 'origin/main'. 4 5nothing to commit, working tree clean 6Everything up-to-date 7successfully push at Thu 08 Sep 2022 11:24:57 AEST
Continue to last and final of the series where, as promised, I would be creating a systemd user service and a timer which will execute script created here in a timely manner everyday, keeping you worry free loosing your unsaved work.comments powered by Disqus