Skip to content

Instantly share code, notes, and snippets.

@kopiro
Last active February 3, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kopiro/675538e2d8faa0b0b48ec5e58ea9f34c to your computer and use it in GitHub Desktop.
Save kopiro/675538e2d8faa0b0b48ec5e58ea9f34c to your computer and use it in GitHub Desktop.
GIT notifications
#!/bin/bash
# For Windows, install https://github.com/Windos/BurntToast first
# Setup
PROJECT_DIR=~/Desktop/test-git
BRANCH_NAME="main"
CHECK_SEC=30
# End setup
cd $PROJECT_DIR
notified_sha=""
notify() {
msg="You have changes to pull ($notified_sha)"
if [ "$(uname)" == "Darwin" ]; then
osascript -e "display notification \"$msg\""
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
notify-send "$msg"
elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
powershell.exe "New-BurntToastNotification -Text \"$msg\""
fi
}
while (true); do
git fetch origin
sha="$(git rev-parse $BRANCH_NAME@{upstream})"
if [ "$(git rev-parse HEAD)" != "$sha" ]; then
if [ "$notified_sha" != "$sha" ]; then
notified_sha="$sha"
notify
fi
fi
sleep $CHECK_SEC
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment