[Linux] Start using git-sync to auto-synchronize directories

This commit is contained in:
Ivan Malison 2018-06-14 16:00:30 -07:00
parent 2d25a8fe19
commit 7371f0aeaa
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
3 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1,12 @@
[Unit]
Description=git-sync %f %I %i
[Service]
Type=simple
ExecStart=/usr/bin/env git_sync_directory.sh %f
ExecStop=/usr/bin/env pkill git_sync_directory.sh
Restart=always
RestartSec=3
[Install]
WantedBy=wm.target

View File

@ -1,11 +1,22 @@
#!/usr/bin/env bash
cd "$1"
#!/usr/bin/env zsh
echo "Syncing $1"
git-sync
enable_git_sync.sh
cd "$1"
while changedFile=$(inotifywait ./ -r -e modify,move,create,delete --format "%w%f" --exclude '\.git' 2>/dev/null); do
git check-ignore "$changedFile" >> /dev/null || git-sync
counter=0
while true; do
changedFile=$(inotifywait ./ -r -e modify,move,create,delete --format "%w%f" --exclude '\.git' -t 20 2>/dev/null)
if [ -z "$changedFile" ]
then
counter=$((counter+1))
if [ $counter -gt 4 ]; then
git-sync
counter=0
else
git-sync > /dev/null
fi
else
echo "Syncing for: $changedFile"
{ git check-ignore "$changedFile" > /dev/null; } || git-sync
fi
done

View File

@ -0,0 +1,17 @@
#!/usr/bin/env sh
enable_git_sync () {
unit_name=$(systemd-escape -p "$1" --template git-sync@.service)
echo $unit_name
systemctl --user enable "$unit_name"
}
unit_name=$(systemd-escape -p "$HOME/.password-store" --template git-sync@.service)
cd "$HOME/.config/systemd/user/"
find * -type f | grep -v git-sync | grep -E "\.service$" | xargs -I unitname sh -c 'echo unitname && systemctl --user enable unitname'
enable_git_sync "$HOME/org"
enable_git_sync "$HOME/config"
enable_git_sync "$HOME/.password-store"