#!/usr/bin/env bash
# sync_all - Update my Vim and Shell repos to latest.

function sync() {
  name=$1
  dir=$2

  if [[ -d $dir ]]; then
    cd $dir
    echo "$name:"
    out=$(git status --porcelain | wc -l 2>&1)
    if [[ $out -ge 1 ]]; then
      echo "	[status] Modified"
    else
      echo "	[status] OK"
    fi
    out=$(git pull 2>&1)
    echo "	[pull] $out"
    out=$(git push 2>&1)
    echo "	[push] $out"
  else
    echo "$name:"
    echo "	Not present on this machine"
  fi
}

pushd ~ &> /dev/null

echo "=> $HOSTNAME"
sync "Settings" ~/Settings
sync "Vim" ~/Vim
sync "Scraps" ~/Projects/scraps/

popd &> /dev/null

