Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- TARGETDIR="$HOME/.config/plover"
- stderr () {
- echo "$1" >&2
- }
- is_command() {
- command -v "$1" &>/dev/null
- }
- if [ "$(uname)" != "Darwin" ]; then
- INW="inotifywait";
- EVENTS="close_write,move,delete,create";
- INCOMMAND="\"$INW\" -qr -e \"$EVENTS\" --exclude \"\.git\" \"$TARGETDIR\""
- else # if Mac, use fswatch
- INW="fswatch";
- # default events specified via a mask, see
- # https://emcrisostomo.github.io/fswatch/doc/1.14.0/fswatch.html/Invoking-fswatch.html#Numeric-Event-Flags
- # default of 414 = MovedTo + MovedFrom + Renamed + Removed + Updated + Created
- # = 256 + 128+ 16 + 8 + 4 + 2
- EVENTS="--event=414"
- INCOMMAND="\"$INW\" --recursive \"$EVENTS\" --exclude \"\.git\" --one-event \"$TARGETDIR\""
- fi
- for cmd in "git" "$INW" "timeout"; do
- # in OSX: `timeout` => brew install coreutils
- # in OSX: `fswatch` => brew install fswatch
- is_command "$cmd" || { stderr "Error: Required command '$cmd' not found"; exit 1; }
- done
- cd "$TARGETDIR"
- echo "$INCOMMAND"
- while true; do
- eval "timeout 20 $INCOMMAND" || true
- if ping -c 1 -w 5 www.google.ca > /dev/null 2>&1; then
- if [[ `git pull | grep "Already up to date."` != "Already up to date." ]]; then
- notify-send -a Plover -u critical "Dictionaries Updated"
- fi
- sleep 5
- STATUS=$(git status -s)
- if [ -n "$STATUS" ]; then
- echo "$STATUS"
- echo "commit!"
- git add .
- git commit -m "Auto-Commit"
- git push origin
- fi
- else
- echo "No connectivity"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment