aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xextract.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/extract.sh b/extract.sh
new file mode 100755
index 0000000..ba611d3
--- /dev/null
+++ b/extract.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+
+set -efu
+
+input_dir=$1
+
+find "$input_dir" -type f |
+ while read -r input_file; do
+ ext=
+ case $input_file in
+ *.elm) ext="elm" ;;
+ *.nix) ext="nix" ;;
+ *) ;;
+ esac
+
+ if test -z $ext; then
+ echo "warning, file $input_file ignored" >&2
+ continue
+ fi
+
+ ./extract-$ext.sh "$input_file"
+ done |
+ while read -r item; do
+ start_row=$(echo "$item" | jq '.match.start.row')
+ end_row=$(echo "$item" | jq '.match.end.row')
+
+ last_commit=$(echo "$item" | jq '.last_commit' -r)
+ text=$(echo "$item" | jq '.text' -r)
+ file=$(echo "$item" | jq '.file' -r)
+
+ first_commit=$(git --no-pager log --reverse -S"$text" --format=%H | \
+ head -n 1)
+
+ created_at=$(git show $first_commit --no-patch --format=%ad)
+ heading=$(echo "$text" | sed '/^$/Q' | sed 's/.*TODO //')
+ body=$(echo "$text" | tail -n +$(($(echo "$heading" | wc -l) + 2)) | \
+ awk -F '[^ ]' '
+ NR == 1 {n = length($1)}
+ {sub("^ {1,"n"}", ""); print}'
+ )
+
+ GREEN='\033[0;32m'
+ BOLD=$(tput bold)
+ NORMAL=$(tput sgr0)
+ NC='\033[0m'
+ echo -e "$GREEN--- $created_at --- $file$NC"
+ echo
+ echo "$BOLD$heading$NORMAL" | fold -s
+ if test -n "$body"; then
+ echo
+ echo "$body" | fold -s
+ echo
+ fi
+ echo
+ cat "$file" | nl -w 4 -s "| " -p -d '' -b a| tail -n +$(($start_row - 2)) | head -n $(($end_row - $start_row + 7))
+ echo
+ echo
+ done