#!/usr/bin/env bash set -efu tree-grepper \ -q elm '([(line_comment) (block_comment)]+)' \ --format json frontend/src/ | \ jq 'sort_by(.file)' | \ jq '.[]' --indent 0 | \ while read -r line; do file=$(echo "$line" | jq -r .file) file_type=$(echo "$line" | jq -r .file_type) items=$(echo "$line" | \ jq '.matches[] | { file: $file, file_type: $file_type, match: . }' --arg file "$file" --arg file_type "$file_type" | \ jq '. | select(.match.text | test("TODO .+"))' ) if test -z "$items"; then continue fi echo "$items" | jq --slurp '.[]' --indent 0 | \ while read -r item; do start_row=$(echo "$item" | jq '.match.start.row') end_row=$(echo "$item" | jq '.match.end.row') last_commit=$(git --no-pager blame -L "$start_row,$start_row" "$file" -p | \ head -n 1 | \ cut -d ' ' -f 1 ) text=$(echo "$item" | \ jq .match.text -r | \ sed 's/^-- //' | \ sed 's/^{- //' | \ sed 's/ -}$//') 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 done