aericktoes

Plover Dictionary Syncer

Feb 3rd, 2021
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. TARGETDIR="$HOME/.config/plover"
  6.  
  7. stderr () {
  8.     echo "$1" >&2
  9. }
  10.  
  11. is_command() {
  12.     command -v "$1" &>/dev/null
  13. }
  14.  
  15. if [ "$(uname)" != "Darwin" ]; then
  16.     INW="inotifywait";
  17.     EVENTS="close_write,move,delete,create";
  18.     INCOMMAND="\"$INW\" -qr -e \"$EVENTS\" --exclude \"\.git\" \"$TARGETDIR\""
  19. else # if Mac, use fswatch
  20.     INW="fswatch";
  21.     # default events specified via a mask, see
  22.     # https://emcrisostomo.github.io/fswatch/doc/1.14.0/fswatch.html/Invoking-fswatch.html#Numeric-Event-Flags
  23.     # default of 414 = MovedTo + MovedFrom + Renamed + Removed + Updated + Created
  24.     #                = 256 + 128+ 16 + 8 + 4 + 2
  25.     EVENTS="--event=414"
  26.     INCOMMAND="\"$INW\" --recursive \"$EVENTS\" --exclude \"\.git\" --one-event \"$TARGETDIR\""
  27. fi
  28.  
  29. for cmd in "git" "$INW" "timeout"; do
  30.     # in OSX: `timeout` => brew install coreutils
  31.     # in OSX: `fswatch` => brew install fswatch
  32.     is_command "$cmd" || { stderr "Error: Required command '$cmd' not found"; exit 1; }
  33. done
  34.  
  35. cd "$TARGETDIR"
  36. echo "$INCOMMAND"
  37.  
  38. while true; do
  39.     eval "timeout 20 $INCOMMAND" || true
  40.     if ping -c 1 -w 5 www.google.ca > /dev/null 2>&1; then
  41.         if [[ `git pull | grep "Already up to date."` != "Already up to date." ]]; then
  42.             notify-send -a Plover -u critical "Dictionaries Updated"
  43.         fi
  44.         sleep 5
  45.         STATUS=$(git status -s)
  46.         if [ -n "$STATUS" ]; then
  47.             echo "$STATUS"
  48.             echo "commit!"
  49.             git add .
  50.             git commit -m "Auto-Commit"
  51.             git push origin
  52.         fi
  53.     else
  54.         echo "No connectivity"
  55.     fi
  56. done
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment