-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommit-org.sh
More file actions
executable file
·34 lines (29 loc) · 820 Bytes
/
commit-org.sh
File metadata and controls
executable file
·34 lines (29 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Customize this path to your org files directory
ORG_DIR="$HOME/.local/Dropbox/Documents/org"
DEBOUNCE_SECONDS=10
LAST_RUN=0
cd "$ORG_DIR" || {
echo "Directory not found: $ORG_DIR"
exit 1
}
# Add all changes
git add .
# Use a timestamp as the commit message
COMMIT_MSG="Auto-commit: $(date '+%Y-%m-%d %H:%M:%S')"
inotifywait -m -r -e close_write,create,delete,move "$ORG_DIR" --exclude ".git/**" |
while read -r directory events filename; do
# Only commit if there are changes
NOW=$(date +%s)
git add .
sleep 1
if ((NOW - LAST_RUN >= DEBOUNCE_SECONDS)) && ! git diff --cached --quiet; then
git commit -m "$COMMIT_MSG"
git pull --rebase # in case of remote changes
git push
echo "Changes committed and pushed."
LAST_RUN=$NOW
else
echo "No changes to commit."
fi
done