-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_template_cli.sh
executable file
·81 lines (65 loc) · 1.77 KB
/
code_template_cli.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
echo "어떤 플랫폼인가요?"
echo "1. LeetCode"
echo "2. 백준 (BOJ)"
read -p "선택: " platform
case $platform in
1) platform="LeetCode" ;;
2) platform="BOJ" ;;
3) platform="Programmers" ;;
*) echo "잘못된 입력입니다." && exit 1 ;;
esac
echo "어떤 언어로 작성하시겠습니까?"
echo "1. Java"
echo "2. Kotlin"
echo "3. Python"
read -p "선택: " language
case $language in
1)
extension="java"
language_name="Java"
;;
2)
extension="kt"
language_name="Kotlin"
;;
3)
extension="py"
language_name="Python"
;;
*)
echo "잘못된 입력입니다."
exit 1
;;
esac
read -p "issue 번호: " issue_number
if [ -z "$issue_number" ]; then
echo "issue 번호는 필수입니다."
exit 1
fi
echo "코드를 입력하세요. 저장하고 에디터를 종료하면 스크립트가 계속됩니다."
tempfile=$(mktemp)
vim "$tempfile"
code=$(cat "$tempfile")
rm "$tempfile"
if [ -z "$code" ]; then
echo "작업이 취소되었습니다."
exit 0
fi
read -p "문제 번호 (optional): " problem_number
read -p "문제 설명 (optional): " problem_description
current_date=$(date +%Y-%m-%d)
folder_name=$platform
file_name="${current_date}_${problem_number:-Unknown}.$extension"
mkdir -p "$folder_name"
echo "$code" > "$folder_name/$file_name"
branch_name="solution/#${issue_number}"
git checkout -b "$branch_name"
git add "$folder_name/$file_name"
commit_message="[#${issue_number}] Add solution for $platform problem #${problem_number:-Unknown} in $language_name"
if [ -n "$problem_description" ]; then
commit_message="$commit_message - $problem_description"
fi
git commit -m "$commit_message"
git push -u origin "$branch_name"
echo "파일 생성 후 브랜치에 커밋 및 푸시되었습니다."