diff options
-rwxr-xr-x | src/anissue.sh | 45 | ||||
-rwxr-xr-x | src/extract-elm.sh | 10 | ||||
-rwxr-xr-x | src/extract-generic.sh | 102 | ||||
-rwxr-xr-x | src/extract-nix.sh | 10 | ||||
-rwxr-xr-x | src/extract-sh.sh | 8 | ||||
-rwxr-xr-x | src/extract.sh | 52 |
6 files changed, 0 insertions, 227 deletions
diff --git a/src/anissue.sh b/src/anissue.sh deleted file mode 100755 index 10736c6..0000000 --- a/src/anissue.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -# Usage: -# anissue -# anissue list -# anissue show - -set -efu - -eval "$(sed -rn '0,/^$/{ /#!/d; s/^# ?//p }' "$0" | docopts -h- : "$@")" - -GREEN='\033[0;32m' -BOLD=$(tput bold) -NORMAL=$(tput sgr0) -NC='\033[0m' - -if test $show = true; then - "$(dirname "$0")"/extract.sh "$@" | while read -r item; do - created_at=$(echo "$item" | jq -r .created_at) - file=$(echo "$item" | jq -r .file) - heading=$(echo "$item" | jq -r .heading) - body=$(echo "$item" | jq -r .body) - start_row=$(echo "$item" | jq -r .start_row) - end_row=$(echo "$item" | jq -r .end_row) - - 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 -else - "$(dirname "$0")"/extract.sh "$@" | while read -r item; do - heading=$(echo "$item" | jq -r .heading) - echo "$heading" - done -fi - -exit 0 diff --git a/src/extract-elm.sh b/src/extract-elm.sh deleted file mode 100755 index 7ab3e17..0000000 --- a/src/extract-elm.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -efu - -TREE_GREPPER_LANGUAGE=elm \ -TREE_GREPPER_QUERY='([(line_comment) (block_comment)])' \ -LINE_COMMENT_START='--' \ -BLOCK_COMMENT_START='{-|\?' \ -BLOCK_COMMENT_END='-}' \ -"$(dirname "$0")"/extract-generic.sh "$@" diff --git a/src/extract-generic.sh b/src/extract-generic.sh deleted file mode 100755 index f4aef22..0000000 --- a/src/extract-generic.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash - -set -efu - -input_file=${1-/dev/stdin} - -# note: merge sibling comments into matched comment blocks, as tree-sitter does -# not allow for matching sibling nodes -function merge_matches() { - matches=$(jq -c .matches[]) - new_matches= - last_match= - new_match= - while read -r cur_match; do - if test -z "$new_match"; then - new_match=$cur_match - fi - if ! test -z "$last_match"; then - last_end_row=$(echo "$last_match" | jq -r .end.row) - cur_start_row=$(echo "$cur_match" | jq -r .start.row) - if test "$(($last_end_row + 1))" = "$cur_start_row"; then - new_text=$(echo "$new_match" | jq -r .text) - cur_text=$(echo "$cur_match" | jq -r .text) - text=$(printf "%s\n%s" "$new_text" "$cur_text") - end=$(echo "$cur_match" | jq -c .end) - new_match=$( - echo "$new_match" | - # XXX "$end" seems to be forbidden as variable name - jq -c \ - --argjson end_ "$end" \ - --arg text "$text" \ - '. + { - "end": $end_, - "text": $text - }' - ) - else - new_matches=$(printf "%s\n%s" "$new_matches" "$new_match") - new_match=$cur_match - fi - fi - last_match=$cur_match - done <<< "$matches" - if ! test -z "$new_match"; then - new_matches=$(printf "%s\n%s" "$new_matches" "$new_match") - fi - new_matches=$(echo "$new_matches" | jq -cs .) - echo "$line" | jq -c --argjson matches "$new_matches" '. + { "matches": $matches }' -} - -tree-grepper \ - --query "$TREE_GREPPER_LANGUAGE" "$TREE_GREPPER_QUERY" \ - --format json $input_file | - jq -c '.[]' | - while read -r line; do - echo "$line" | merge_matches - done | 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/^'"$LINE_COMMENT_START"'\( *TODO *\| \?\)//g' | - { - if test -z "${BLOCK_COMMENT_START-}"; then - cat - else - sed 's/^'"$BLOCK_COMMENT_START"'\( *TODO *\| \?\)//' - fi - } | - { - if test -z "${BLOCK_COMMENT_END-}"; then - cat - else - sed 's/ *'"$BLOCK_COMMENT_END"' *$//' - fi - } - ) - - echo "$item" | jq '. + {"text": $text, "last_commit": $last_commit}' \ - --arg text "$text" \ - --arg last_commit "$last_commit" \ - -c - done - done diff --git a/src/extract-nix.sh b/src/extract-nix.sh deleted file mode 100755 index 575131d..0000000 --- a/src/extract-nix.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -efu - -TREE_GREPPER_LANGUAGE=nix \ -TREE_GREPPER_QUERY='(comment)' \ -LINE_COMMENT_START='#' \ -BLOCK_COMMENT_START='\/\*' \ -BLOCK_COMMENT_END='\*\/' \ -"$(dirname "$0")"/extract-generic.sh "$@" diff --git a/src/extract-sh.sh b/src/extract-sh.sh deleted file mode 100755 index a8bb1ff..0000000 --- a/src/extract-sh.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -efu - -TREE_GREPPER_LANGUAGE=sh \ -TREE_GREPPER_QUERY='(comment)' \ -LINE_COMMENT_START='#' \ -"$(dirname "$0")"/extract-generic.sh "$@" diff --git a/src/extract.sh b/src/extract.sh deleted file mode 100755 index cd5cb67..0000000 --- a/src/extract.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -set -efu - -git ls-files --cached --exclude-standard --other | - while read -r input_file; do - ext= - case $input_file in - *.elm) ext="elm" ;; - *.nix) ext="nix" ;; - *.sh) ext="sh" ;; - *) ;; - esac - - if test -z $ext; then - echo "warning, file $input_file ignored" >&2 - continue - fi - - "$(dirname "$0")"/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 -n '0,/^$/p') - body=$(echo "$text" | tail -n +$(($(echo "$heading" | wc -l) + 2))) - - echo "$item" | jq -c \ - --arg body "$body" \ - --arg created_at "$created_at" \ - --arg first_commit "$first_commit" \ - --arg heading "$heading" \ - --argjson end_row "$end_row" \ - --argjson start_row "$start_row" \ - '. + { - "body": $body, - "created_at": $created_at, - "end_row": $end_row, - "first_commit": $first_commit, - "heading": $heading, - "start_row": $start_row - }' - done |