-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstart-new-dojo
executable file
·75 lines (58 loc) · 1.44 KB
/
start-new-dojo
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
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# set -o xtrace
COLOR_ORANGE="\x1B[1;33m"
COLOR_BLUE="\x1B[1;34m"
COLOR_RESET="\x1B[0m"
warn() {
echo -e "${COLOR_ORANGE}${*}${COLOR_RESET}"
}
info() {
echo -e "${COLOR_BLUE}${*}${COLOR_RESET}"
}
_get_first() {
head -n1
}
last_readme() {
ls -r -d 20*/*/*/README.md |
_get_first |
xargs cat
}
_filter_subjects() {
grep -E "[[:digit:]]+[[:space:]]*-[[:space:]]*[[:alpha:]][[:space:]]*"
}
_sort_subjects() {
sort -k2 -r -b -n
}
_extract_subject() {
sed -E "s/^.*[[:digit:]]+[[:space:]]*-([[:space:]]*[[:alpha:]][[:space:]]*-)?[[:space:]]*//"
}
elected_subject() {
_filter_subjects |
_sort_subjects |
_extract_subject |
_get_first
}
create_today_folder() {
TODAY="$1"
mkdir -p "${TODAY}"
cp README.md "${TODAY}/"
git add --intent-to-add "${TODAY}/"
}
replace_in_place() {
PATTERN="$1"
FILE="$2"
TEMPORARY_FILE="${FILE}_without_problem_on_mac_os_x"
sed "${PATTERN}" <"${FILE}" >"${TEMPORARY_FILE}"
mv "${TEMPORARY_FILE}" "${FILE}"
}
main() {
LAST_SUBJECT=$(last_readme | elected_subject)
info "the last elected subject was : ${LAST_SUBJECT}"
TODAY=$(date "+%Y/%m/%d")
info "create a new folder for today ${TODAY}"
create_today_folder "${TODAY}"
info "filling README with previous subject"
replace_in_place "s/Ancien sujet/${LAST_SUBJECT}/" "${TODAY}/README.md"
}
main