-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_logger.sh
executable file
·58 lines (50 loc) · 1.64 KB
/
git_logger.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
# if [[ "$1" == "add" || "$1" == "commit" || "$1" == "push" || "$1" == "status" ]]; then
# # Do not log these commands, just pass them to git
# git "$@"
# else
# # Log the command (with date and time) and pass it to git
# git "$@"
# exit_status=$?
# # If the exit status is 0 (success), log the command
# #echo $exit_status
# if [ $exit_status -eq 0 ]; then
# echo "$(date) git $@" >> ~/gitcounter/frequency.log
# else
# echo "git-logger: The git command failed and will not be logged"
# fi
# #echo "$(date) git $@" >> ~/gitcounter/frequency.log
# exit $exit_status
# fi
ignore_file="/Users/jamesroot/gitcounter/.counterignore"
if [[ -f "$ignore_file" ]]; then
# Read the ignored keywords into an array
IFS=$'\n' read -d '' -r -a ignored_keywords < "$ignore_file"
# else
# # If the file doesn't exist, exit with an error
# echo "Error: .counterignore file not found at $ignore_file"
# exit 1
fi
is_ignored_command() {
for keyword in "${ignored_keywords[@]}"; do
if [[ "$1" == "$keyword" ]]; then
return 0 # Command is ignored
fi
done
return 1 # Command is not ignored
}
if is_ignored_command "$1"; then
# Do not log these commands, just pass them to git
git "$@"
else
# Log the command (with date and time) and pass it to git
git "$@"
exit_status=$?
# If the exit status is 0 (success), log the command
#echo $exit_status
if [ $exit_status -eq 0 ]; then
echo "$(date) git $@" >> /Users/jamesroot/gitcounter/frequency.log
else
echo "git-logger: The git command failed and will not be logged"
fi
exit $exit_status
fi