-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitcc
More file actions
executable file
·117 lines (91 loc) · 2.5 KB
/
gitcc
File metadata and controls
executable file
·117 lines (91 loc) · 2.5 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
# Git Commit Check (gitcc)
# Version: 0.5.0
# Github repo: https://github.com/angtheod/git-commit-check
# Author: Angelos Theodorakopoulos <angtheod@gmail.com>
# Change to the directory of the script and source the required scripts.
cd "$(dirname "$0")" || exit 1
. ./config.sh
cd "$(dirname "$0")" || exit 1
. ./lib.sh
init() {
START=$(date +%s)
HAS_ERRORS=0
HAS_SYNTAX_ERRORS=0
}
header() {
line3 "╔" "╗" $((WIDTH+8)) "═"
printf " %s${CYAN}Load\n" "$SECTION_SYMBOL"
line "Configuration" "${1:-./config.sh}"
}
check() {
[ -n "$ENABLED" ] && printf "\n %s${CYAN}Check${NC}\n" "$SECTION_SYMBOL"
for script in $(find "$GITCC_SCRIPTS_PATH" -type f -name '*.sh' | sort); do
_name=$(basename "$script")
_id="${_name%%_*}"
# Check if the script is enabled in the configuration and then source the script
# so that it runs in the same shell process and the variables are accessible within it.
if contains_string "$_id" "$ENABLED"; then
before_run_check "$script"
run_check
after_run_check
fi
done
}
before_run_check() {
if [ $# -eq 0 ]; then
printf "(Unknown)\n"
return 1
fi
script=$1
# Initialise variables.
HEADER=""
COMMAND_NAME=""
COMMAND_VERSION=""
unset -f after_run # Clear the 'after_run' shell function before sourcing the script.
. "$script"
before_run # Call user's before run function.
line2 "$HEADER" "$LOAD_SYMBOL"
}
run_check() {
run
}
after_run_check() {
if [ "$COMMAND_NAME" != "" ] && [ "$COMMAND_VERSION" != "" ]; then
add_about_info "$COMMAND_NAME" "$COMMAND_VERSION"
fi
if type after_run > /dev/null 2>&1; then # Call the function 'after_run' only if the script implements it.
after_run
fi
}
about() {
if [ "$SHOW_ABOUT" = 0 ] || [ -z "$ABOUT" ]; then
return
fi
printf "\n %s${CYAN}About\n" "$SECTION_SYMBOL"
split_about_info | while IFS='|' read -r left right; do
line "$left" "$(extract_version "$right")"
done
}
footer() {
line3 "╚" "╝" $((WIDTH+8)) "═"
END=$(date +%s)
time=$((END-START))
if [ "$SHOW_LOG_URL" -eq 1 ]; then
line3 "$LOG_SYMBOL $LOG_URL" "$TIME_SYMBOL ${time}sec" "$((WIDTH+7))" " "
else
line3 "" "$TIME_SYMBOL ${time}sec" "$((WIDTH+7))" " "
fi
}
main() {
init
header
check
about
footer
if [ "$HAS_ERRORS" -ne 0 ]; then
exit 1
fi
}
main
exit $?