-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.sh
More file actions
executable file
·47 lines (43 loc) · 1.23 KB
/
Copy pathtodo.sh
File metadata and controls
executable file
·47 lines (43 loc) · 1.23 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
#!/bin/bash
# Scan source base for lines containing // TODO
# and compile a list to be inserted into the
# target file.
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` target-file"
exit 1
else
target="$1"
fi
directories='Cea/ tests/'
list=$(grep -r TODO $directories | sed -e 's/[ \t]*\/\/ TODO//' -e 's/^/+ /')
# Escape underscores and asterisks, then ermove double \\.
list=$(echo "$list" | sed -e 's/_/\\_/g' -e 's/\*/\\\*/g')
list=$(echo "$list" | sed -e 's/\\\\//g')
# Appends list under a todo list heading to file f.
output()
{
echo 'Todo List' >> $f
echo '---------' >> $f
echo >> $f
echo "$list" >> $f
}
if [ -e $target ]; then
if [ $(grep -c 'Todo List' $target) -gt 0 ]; then
# At least 1 todo list heading found. Delete everything after it!
delete_from=$(grep -m 1 -n 'Todo List' $target | sed -e 's/:.*$//')
temp_target='/var/tmp/temp_'$target''
sed -e ''$delete_from',$d' $target > $temp_target
f=$temp_target
output
mv -f $temp_target $target
else
# No todo list found - append this one.
echo >> $target
f=$target
output
fi
else
# No target - make one with the todo list in.
f=$target
output
fi