Skip to content

Instantly share code, notes, and snippets.

@alexandru
Last active December 2, 2020 22:33
Show Gist options
  • Save alexandru/5d2bdf9fa29d62987b33324de73cbd81 to your computer and use it in GitHub Desktop.
Save alexandru/5d2bdf9fa29d62987b33324de73cbd81 to your computer and use it in GitHub Desktop.

See context.

To configure this script to automatically execute on file changes, save the XML config in ~/Library/LaunchAgents/dot-files.sync.plist then do:

launchctl load -w ~/Library/LaunchAgents/dot-files.sync.plist
<?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>dot-files.sync</string>
<key>ProgramArguments</key>
<array>
<string>/Users/alex/Projects/dot-files/sync-repo.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/alex/Projects/dot-files</string>
</array>
<key>ThrottleInterval</key>
<integer>30</integer>
<key>StandardOutPath</key>
<string>/Users/alex/bin/log/sync-dot-files.log</string>
<key>StandardErrorPath</key>
<string>/Users/alex/bin/log/sync-dot-files.log</string>
</dict>
</plist>
#!/usr/bin/env bash
set -e
cleanup()
{
echo "Cleaning up ..."
if [ -n "$SSH_AGENT_PID" ]; then
echo "Killing ssh-agent PID $SSH_AGENT_PID"
kill "$SSH_AGENT_PID"
else
echo "WARN: SSH_AGENT_PID not set!"
fi
}
trap cleanup EXIT
export PATH="$HOME/bin:/usr/local/bin:/usr/local/sbin:$PATH"
echo "----------------------"
date
echo "..."
eval $(ssh-agent -s)
ssh-add -K
echo "Synchronizing dot-files"
cd /Users/alex/Projects/personale/dot-files
git-sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment