-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitnotify.sh
executable file
·64 lines (59 loc) · 2.5 KB
/
gitnotify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# This file is part of Git-Notifier.
#
# Git-Notifier is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.
#
# Git-Notifier is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Git-Notifier. If not, see <http://www.gnu.org/licenses/>.
#Check that we have a ~/.gitnotify directory. Make it if we don't
if [[ ! -d ~/.gitnotify ]]; then
mkdir ~/.gitnotify
fi
#Initialize gitnotify
GN_INI_FILE=~/.gitnotify/gitnotify.ini
GN_REPOS=`cat $GN_INI_FILE | grep ^repos= | sed -u 's/repos=//g'`
GN_DURATION=`cat $GN_INI_FILE | grep ^duration= | sed -u 's/duration=//g'`
GN_PRETTY=`cat $GN_INI_FILE | grep ^pretty= | sed -u 's/pretty=//g'`
declare -A GN_LASTSHOW
#Initialize LASTSHOW array
for GN_REPO in $GN_REPOS; do
if [[ -d ~/.gitnotify/$GN_REPO ]] ; then
cd ~/.gitnotify/$GN_REPO
for GN_BRANCH in `git branch -a | grep remotes/ | sed 's/ -> .*//' | sed 's/^ //'`; do
GN_BRANCH_ARRAY=`echo ${GN_BRANCH} | sed 's/\//_/g'`
GN_LASTSHOW[${GN_REPO}_${GN_BRANCH_ARRAY}]=`git log $GN_BRANCH --pretty=$GN_PRETTY -1`
done
else
echo Unable to locate ~/.gitnotify/$GN_REPO repository >> ~/.gitnotify/log
fi
done
#Check for updates and notify when necessary
while true; do
for GN_REPO in $GN_REPOS; do
if [[ -d ~/.gitnotify/$GN_REPO ]]; then
cd ~/.gitnotify/$GN_REPO
git fetch
#Loop through all of the local branches in the repository
for GN_BRANCH in `git branch -a | grep remotes/ | sed 's/ -> .*//' | sed 's/^ //'`; do
GN_GITSHOW=`git log $GN_BRANCH --pretty=$GN_PRETTY -1`
GN_BRANCH_ARRAY=`echo ${GN_BRANCH} | sed 's/\//_/g'`
if [ "${GN_LASTSHOW[${GN_REPO}_${GN_BRANCH_ARRAY}]}" != "$GN_GITSHOW" ]; then
notify-send -i gtk-dialog-info -t 300000 -- "Git Update - $GN_REPO" "$GN_GITSHOW"
fi
GN_LASTSHOW[${GN_REPO}_${GN_BRANCH_ARRAY}]=$GN_GITSHOW
done
else
echo Unable to locate ~/.gitnotify/$GN_REPO repository. Please update ~/.gitnotify/gitnotify.ini >> ~/.gitnotify/log
#Only keep the last thirty logs
tail -n 30 ~/.gitnotify/log > ~/.gitnotify/log
fi
done
sleep $GN_DURATION
done