aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/extract-elm.sh46
-rwxr-xr-xsrc/extract-generic.sh44
-rwxr-xr-xsrc/extract-nix.sh46
3 files changed, 56 insertions, 80 deletions
diff --git a/src/extract-elm.sh b/src/extract-elm.sh
index 375d8a8..9fe1d4c 100755
--- a/src/extract-elm.sh
+++ b/src/extract-elm.sh
@@ -2,43 +2,9 @@
set -efu
-input_file=${1-/dev/stdin}
-
-tree-grepper \
- --query elm '([(line_comment) (block_comment)]+)' \
- --format json $input_file |
- 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/^-- *TODO *//' |
- sed 's/^{-|\? *TODO *//' |
- sed 's/ *-}$//')
-
- echo "$item" | jq '. + {"text": $text, "last_commit": $last_commit}' \
- --arg text "$text" \
- --arg last_commit "$last_commit" \
- -c
- done
- done
+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
new file mode 100755
index 0000000..0c84ec1
--- /dev/null
+++ b/src/extract-generic.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+set -efu
+
+input_file=${1-/dev/stdin}
+
+tree-grepper \
+ --query "$TREE_GREPPER_LANGUAGE" "$TREE_GREPPER_QUERY" \
+ --format json $input_file |
+ 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/^'"$LINE_COMMENT_START"' *TODO *//' |
+ sed 's/^'"$BLOCK_COMMENT_START"' *TODO *//' |
+ sed 's/ *'"$BLOCK_COMMENT_END"'$//')
+
+ 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
index e092db2..335cbba 100755
--- a/src/extract-nix.sh
+++ b/src/extract-nix.sh
@@ -2,43 +2,9 @@
set -efu
-input_file=${1-/dev/stdin}
-
-tree-grepper \
- --query nix '((comment)+)' \
- --format json $input_file |
- 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/^# *TODO *//' |
- sed 's/^\/\* *TODO *//' |
- sed 's/ *\*\/$//')
-
- echo "$item" | jq '. + {"text": $text, "last_commit": $last_commit}' \
- --arg text "$text" \
- --arg last_commit "$last_commit" \
- -c
- done
- done
+TREE_GREPPER_LANGUAGE=nix \
+TREE_GREPPER_QUERY='((comment)+)' \
+LINE_COMMENT_START='#' \
+BLOCK_COMMENT_START='\/\*' \
+BLOCK_COMMENT_END='\*\/' \
+"$(dirname "$0")"/extract-generic.sh "$@"