-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_example.sh
More file actions
executable file
·52 lines (42 loc) · 1.05 KB
/
Copy pathnew_example.sh
File metadata and controls
executable file
·52 lines (42 loc) · 1.05 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
#!/bin/bash
# new_example.sh - Create a new example from a template
# Usage: ./new_example.sh <asm|c> [name]
# If name is omitted, today's date (yyyy-mm-dd) is used.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TYPE="$1"
NAME="${2:-$(date +%Y-%m-%d)}"
if [ -z "$TYPE" ]; then
echo "Usage: $0 <asm|c> [name]"
exit 1
fi
case "$TYPE" in
asm)
TEMPLATE_DIR="$SCRIPT_DIR/asm_template"
EXAMPLES_DIR="$SCRIPT_DIR/asm_examples"
MAIN_SRC="_main.asm"
MAIN_DST="main.asm"
;;
c)
TEMPLATE_DIR="$SCRIPT_DIR/c_template"
EXAMPLES_DIR="$SCRIPT_DIR/c_examples"
MAIN_SRC="_main.c"
MAIN_DST="main.c"
;;
*)
echo "Error: type must be 'asm' or 'c' (got '$TYPE')"
exit 1
;;
esac
DEST="$EXAMPLES_DIR/$NAME"
if [ -e "$DEST" ]; then
echo "Error: '$DEST' already exists"
exit 1
fi
cp -r "$TEMPLATE_DIR" "$DEST"
mv "$DEST/$MAIN_SRC" "$DEST/$MAIN_DST"
mkdir -p "$DEST/output"
cat > "$DEST/README.md" <<EOF
# $NAME
EOF
echo "Created $TYPE example: $DEST"