aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--pkgs/tree-grepper.nix7
-rwxr-xr-xsrc/extract-generic.sh17
-rwxr-xr-xsrc/extract-sh.sh8
-rwxr-xr-xsrc/extract.sh1
-rw-r--r--tests/sh.sh11
6 files changed, 45 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index ef3ecb6..35aa2e3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,9 @@
-test: test-elm test-nix
+test: test-sh test-elm test-nix
+
+test-sh: tests/sh.sh
+ src/extract-sh.sh tests/sh.sh | \
+ jq .text -r | \
+ cmp tests/expect
test-elm: tests/elm.elm
src/extract-elm.sh tests/elm.elm | \
diff --git a/pkgs/tree-grepper.nix b/pkgs/tree-grepper.nix
index 591bc7e..463bf6c 100644
--- a/pkgs/tree-grepper.nix
+++ b/pkgs/tree-grepper.nix
@@ -1,9 +1,10 @@
self: super: {
# TODO package tree-grepper in Nixpkgs so that it can reuse <nixpkgs>
tree-grepper = (import (self.fetchFromGitHub {
- owner = "BrianHicks";
+ owner = "aforemny";
repo = "tree-grepper";
- rev = "refs/tags/2.4.1";
- hash = "sha256-wHqVhx2JFBm+lc3/rruBBlpF2Ylv3/oOFM5CgX5WtKs=";
+ rev = "af9d7e4380f5c1b12bc671216a219c1f01a640d7";
+ hash = "sha256-QteyQ/SfcXZ2VZTRl++gRHeaR/1qnsS8tiN1RLndW5Y=";
})).default;
}
+
diff --git a/src/extract-generic.sh b/src/extract-generic.sh
index 0c84ec1..cadbb30 100755
--- a/src/extract-generic.sh
+++ b/src/extract-generic.sh
@@ -33,8 +33,21 @@ tree-grepper \
text=$(echo "$item" |
jq .match.text -r |
sed 's/^'"$LINE_COMMENT_START"' *TODO *//' |
- sed 's/^'"$BLOCK_COMMENT_START"' *TODO *//' |
- sed 's/ *'"$BLOCK_COMMENT_END"'$//')
+ {
+ 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" \
diff --git a/src/extract-sh.sh b/src/extract-sh.sh
new file mode 100755
index 0000000..c31df74
--- /dev/null
+++ b/src/extract-sh.sh
@@ -0,0 +1,8 @@
+#!/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
index ce5c4d0..07eac37 100755
--- a/src/extract.sh
+++ b/src/extract.sh
@@ -14,6 +14,7 @@ find "$input_dir" -type f | grep -Pv '/\.|~$' |
case $input_file in
*.elm) ext="elm" ;;
*.nix) ext="nix" ;;
+ *.sh) ext="sh" ;;
*) ;;
esac
diff --git a/tests/sh.sh b/tests/sh.sh
new file mode 100644
index 0000000..9e7c51d
--- /dev/null
+++ b/tests/sh.sh
@@ -0,0 +1,11 @@
+#! /usr/bin/env bash
+
+# TODO add more dependencies
+export PATH=
+
+# TODO remove unnecessary content
+cat >/dev/null <<'EOF'
+ sssh!
+EOF
+
+exit 0