Michael Hoennig
2022-08-04 45c1bed43bd26ee94b4a625c29a20713666eb442
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
#!/bin/bash
# check if required programs are installed
declare -a required=(gnuplot sponge)
for cmd in "${required[@]}"; do
    command -v $cmd >/dev/null 2>&1 || { echo >&2 "Required '$cmd' not installed => aborting."; exit 1; }
done
 
# calculate current values
let budget=`grep '^| ... |' <TODO.md | rev | cut -d'|' -f4 | rev | grep -o '[[:digit:]]*' | total`
let effort=`grep '^| ... |' <TODO.md | rev | cut -d'|' -f3 | rev | grep -o '[[:digit:]]*' | total`
let output=`grep '^| ... |' <TODO.md | rev | cut -d'|' -f2 | rev | grep -o '[[:digit:]]*' | total`
let remainder=$(expr $budget - $output)
 
# generating progress report
echo '<!-- generated todo-progress begin: -->' >.todo-progress.md
sed -e '1,/todo-progress begin:/d' -e '/todo-progress end./,$d' TODO.md >>.todo-progress.md
if [ "$1" = "--recalculate" ]; then
    echo "| $(date --iso-8601) | $(printf "%6d" $budget) | $(printf "%7d" $effort) | $(printf "%8d" $output) | $(printf "%11d" $remainder) |" >>.todo-progress.md
fi
echo '<!-- generated todo-progress end. -->' >>.todo-progress.md
 
# replace the generated todo-progress part
if [ "$1" = "--recalculate" ]; then
    uniq <.todo-progress.md | sponge .todo-progress.md
    sed -i -e '/todo-progress begin:/,/todo-progress end./!b' -e '/todo-progress end./!d;r .todo-progress.md' -e 'd' TODO.md
fi
 
# re-generate progress chart
sed -e's/^|//' <.todo-progress.md | tr '|' ';' | grep ';' | grep -v -- '---' >.todo-progress.csv
gnuplot tools/todo-progress.gnuplot
rm .todo-progress.md .todo-progress.csv
 
echo "HINT: To recalculate the current values and add a new line, use '$0 --recalculate'."