-
Notifications
You must be signed in to change notification settings - Fork 0
/
rust_template.sh
executable file
·115 lines (80 loc) · 1.77 KB
/
rust_template.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
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
#!/bin/bash
#
# Create rust template
d=$(basename $PWD)
if [[ $# -ne 1 ]]; then
printf "usage:\n $0 [name]\n"
exit 1
fi
echo "Creating empty rust project \"$1\" for day $d"
cargo new "$1" --bin
cat > "./$1/src/main.rs" << EOF
/* Advent of code */
/* day $d */
use std::io;
use std::io::BufRead;
fn main () {
read_stdin();
part1();
part2();
}
fn part1() {
}
fn part2() {
}
fn read_stdin() {
let std = io::stdin();
for l in std.lock().lines() {
let l = l.unwrap();
println!("{}", l);
}
}
EOF
echo '.*.sw*' > .gitignore
echo ".git_template" >> .gitignore
cat > Makefile << EOF
day=$d
target=debug
debug_target=./$1/target/debug/$1
release_target=./$1/target/release/$1
src=./$1/src/main.rs
\$(debug_target): \$(src)
cd $1 && cargo build
\$(release_target): \$(src)
cd $1 && cargo build --release
debug: \$(debug_target)
\$(debug_target)
release: \$(release_target)
\$(release_target)
$1: \$(target)
all: $1
vi:
vi \$(src)
.git_template:
echo "\$(day): " > .git_template
commit: .git_template
git commit -st .git_template
add:
git add \$(src)
git diff --cached
amend:
git commit --amend --no-edit
autocommit: add commit
autocommit_out: .git_template \$(debug_target)
cat .git_template > /tmp/commit_template
echo "" >> /tmp/commit_template
echo " \\$\$ \$(debug_target)" >> /tmp/commit_template
\$(debug_target) | sed 's/^/ /' >> /tmp/commit_template
git commit -st /tmp/commit_template
test: \$(debug_target)
cat test.txt | \$(debug_target)
test_release: \$(release_target)
cat test.txt | \$(release_target)
run: \$(debug_target)
cat input.txt | \$(debug_target)
run_release: \$(release_target)
cat input.txt | \$(release_target)
EOF
git add Makefile "$1" .gitignore
git ct -m "$d: add rust template"
# TODO: Automatically commit output