Skip to content

Instantly share code, notes, and snippets.

@kevin-smets
Last active June 8, 2022 08:22
Show Gist options
  • Save kevin-smets/5c997b31d3ef990fcfbc96cdd7d723f9 to your computer and use it in GitHub Desktop.
Save kevin-smets/5c997b31d3ef990fcfbc96cdd7d723f9 to your computer and use it in GitHub Desktop.
Feeling homeSync? Sync your home dir to a git repo with launchd every 30 minutes (macOS)

Feeling homeSync?

  1. Place homeSync.sh and homeSync.plist in your home dir
cd ~
git init
git remote add origin <https://your/git/repo.git>

cp homeSync.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homeSync.plist

Recommended to place the following .gitignore in ~/ as well:

/*
!.bashrc
!.bash_history
!.gitignore
# Depending on your shell usage etc
!.zshrc
!.zsh_history
!homeSync.plist
!homeSync.sh

/*/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homeSync</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>~/homeSync.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/homeSync.err</string>
<key>StandardOutPath</key>
<string>/tmp/homeSync.out</string>
<key>StartInterval</key>
<integer>1800</integer>
</dict>
</plist>
cd
git add .
git commit -m "Auto sync @ $(date)"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment