-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_new_header.sh
executable file
·60 lines (48 loc) · 1.01 KB
/
create_new_header.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
#!/bin/sh -e
if [ -z "$1" ]; then
echo "usage: $0 filename.hh"
exit 1
fi
if [ "$(git rev-parse --show-toplevel)" != "$(pwd)" ]; then
echo "ERROR: you need to execute this in project root"
exit 1
fi
if [ -e "$1" ]; then
echo "ERROR: file $1 allready exists"
exit 2
fi
file=$1
name=$file
name=${name#./}
name=${name%.hh}
if [ "${name#/}" != "$name" ]; then
echo "ERROR: absolute paths are not ok."
exit 1
fi
if [ "$name" != "${name#*/*}" ]; then
dir=$(echo "$name" | sed 's,/[^/]*$,/,g')
else
dir=""
fi
upper=$(echo "$name" | sed 's,/,__,g' | tr '[a-z]' '[A-Z]')
prefix=$(echo "$dir" | sed 's,[^/]*/,../,g')
if [ "$dir"] && ! [ -d "$dir" ]; then
mkdir -p "$dir"
echo "Created directory: ${dir%/}"
fi
cat > "$file" <<EOF
#ifndef __YAAL_${upper}__
#define __YAAL_${upper}__ 1
#include "${prefix}requirements.hh"
#ifdef __YAAL__
namespace yaal {
/* ... */
}
#endif
#endif
EOF
echo "Created file $file"
echo "---"
cat "$file"
echo "---"
git add "$file" && echo "Added it to git"