diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-09-06 11:03:36 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-09-06 11:38:38 +0200 |
commit | 62df7214a1b6602bec3e355a0729de2968db6504 (patch) | |
tree | 0bd9e4eb965e40a3c9582371b0b45f9671b0320a | |
parent | ea5ff5547b365964ff2c0215caa3a2a020b6d7ed (diff) |
add support for .sh files
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | pkgs/tree-grepper.nix | 7 | ||||
-rwxr-xr-x | src/extract-generic.sh | 17 | ||||
-rwxr-xr-x | src/extract-sh.sh | 8 | ||||
-rwxr-xr-x | src/extract.sh | 1 | ||||
-rw-r--r-- | tests/sh.sh | 11 |
6 files changed, 45 insertions, 6 deletions
@@ -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 |