-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·35 lines (28 loc) · 1.85 KB
/
pre-commit
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
#!/bin/sh
script=$(readlink "$0")
script_directory=$(dirname "$script") # Thanks: http://stackoverflow.com/questions/242538/unix-shell-script-find-out-which-directory-the-script-file-resides
working_directory="${script_directory}/commit-log/"
sound_path="${script_directory}/sounds/music_marimba_chord.wav"
name=$(git config user.name) # Thanks: http://stackoverflow.com/questions/7552054/git-cli-get-user-info-from-username
commit_id=$(git log --format="%H" -n 1) # Thanks: http://stackoverflow.com/questions/19176359/how-to-get-the-last-commit-id-of-a-remote-repo-using-curl-like-command
repository_name=$(basename `git rev-parse --show-toplevel`) # Thanks: http://stackoverflow.com/questions/15715825/how-do-you-get-git-repos-name-in-some-git-repository
now=$(date +%Y-%m-%d:%H:%M:%S) # Thanks: http://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script
geo_location=$(/usr/local/bin/LocateMe -f {LAT},{LON})
latitude=$(cut -d"," -f1 <<<"${geo_location}") # Thanks: https://unix.stackexchange.com/questions/312280/split-string-by-delimiter-and-get-n-th-element
longitude=$(cut -d"," -f2 <<<"${geo_location}") # Thanks: https://unix.stackexchange.com/questions/312280/split-string-by-delimiter-and-get-n-th-element
if [ -n "$commit_id" ]; then
log_file_path="${working_directory}/${commit_id}.geoLocation"
output="{
\"commit_id\": \"${commit_id}\",
\"repository_name\": \"${repository_name}\",
\"date\": \"${now}\",
\"latitude\": \"${latitude}\",
\"longitude\": \"${longitude}\",
\"name\": \"${name}\"
}"
echo $output
echo $output > $log_file_path
afplay $sound_path
else
echo "no commit found"
fi