[Linux] Start using git-sync to auto-synchronize directories
This commit is contained in:
parent
2d25a8fe19
commit
7371f0aeaa
12
dotfiles/config/systemd/user/git-sync@.service
Normal file
12
dotfiles/config/systemd/user/git-sync@.service
Normal 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
|
@ -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
|
||||
|
17
tasks/shell/enable_user_units.sh
Executable file
17
tasks/shell/enable_user_units.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user