Created
May 30, 2023 14:37
-
-
Save raghavauppuluri13/c55d5a6a820d75926472089c0d842f06 to your computer and use it in GitHub Desktop.
Push/pull on obsidian open/close
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
repo_path="/home/raghava/knowledge_vault" | |
branch="master" | |
commit_message="update" | |
state_file="/tmp/running-obsidian-state.txt" | |
while true; do | |
if [ ! -f "$state_file" ]; then | |
echo "not_running" > "$state_file" | |
fi | |
old_state=$(cat "$state_file") | |
new_state="not_running" | |
if ps aux | grep -v grep | grep Obsidian > /dev/null; then | |
new_state="running" | |
fi | |
if [ "$old_state" != "$new_state" ]; then | |
if [ "$new_state" = "running" ] ; then | |
echo "Obsidian is running!" | |
notify-send "Git pull started" "Pulling changes from $branch branch..." | |
cd "$repo_path" | |
if ! git pull origin "$branch"; then | |
notify-send "Git pull error" "Failed to pull changes from $branch branch." | |
else | |
notify-send "Git pull complete" "Changes pulled from $branch branch." | |
fi | |
else | |
echo "Obsidian is not running." | |
notify-send "Git commit started" "Committing changes to $branch branch..." | |
cd "$repo_path" | |
git add . | |
git commit -m "$commit_message" | |
if ! git push origin "$branch"; then | |
notify-send "Git push error" "Failed to push changes to $branch branch." | |
else | |
notify-send "Git push complete" "Changes pushed to $branch branch." | |
fi | |
fi | |
echo "$new_state" > "$state_file" | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment