-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_leetcode.sh
More file actions
executable file
·63 lines (53 loc) · 1.54 KB
/
Copy pathcommit_leetcode.sh
File metadata and controls
executable file
·63 lines (53 loc) · 1.54 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
#!/bin/bash
# stop on first error & pipe fail
set -e
set -o pipefail
function usage() {
echo "Usage: $0 [--help] question_numbers..."
echo " Utilities to add one or more LeetCode solutions to the project."
echo " -h, --help"
echo " Print this message and exit."
}
# If no arguments are given, print usage and exit
if [ $# -eq 0 ]; then
usage
exit 1
fi
# Parse options
QUESTION_NUMBERS=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
*)
# Treat every non-option argument as a question number
QUESTION_NUMBERS+=("$1")
shift
;;
esac
done
CURRENT_DATE=$(date +"%Y-%m-%d")
# For each question number, confirm, then commit
for QUESTION_NUMBER in "${QUESTION_NUMBERS[@]}"; do
if [ ! -e "q${QUESTION_NUMBER}.cpp" ]; then
echo "The cpp answer for q${QUESTION_NUMBER} does not exist."
continue
fi
while true; do
read -r -p "Committing q${QUESTION_NUMBER} ... Confirm? [Y]/n " CONFIRMATION
CONFIRMATION=${CONFIRMATION:-Y}
if [[ "$CONFIRMATION" =~ ^[Yy]$ ]]; then
break
elif [[ "$CONFIRMATION" =~ ^[Nn]$ ]]; then
echo "Skipping q${QUESTION_NUMBER}"
continue 2 # move on to the next QUESTION_NUMBER
else
echo "Invalid input. Please enter Y for yes or N for no."
fi
done
TEMPLATE_GIT_COMMIT_MSG="daily leetcode ${CURRENT_DATE} (q${QUESTION_NUMBER})"
git add "q${QUESTION_NUMBER}.cpp" CMakeLists.txt
git commit -m "${TEMPLATE_GIT_COMMIT_MSG}"
done