aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--anissue.nix5
-rw-r--r--shell.nix1
-rwxr-xr-xsrc/anissue.sh45
-rwxr-xr-xsrc/extract.sh32
5 files changed, 59 insertions, 34 deletions
diff --git a/README.md b/README.md
index b5c8079..30e5135 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,14 @@ nix-env -f. -i
## usage
+### list
+
+```console
+anissue list
+```
+
+### show
+
```console
-anissue .
+anissue show
```
diff --git a/anissue.nix b/anissue.nix
index e0c3496..c2113f0 100644
--- a/anissue.nix
+++ b/anissue.nix
@@ -1,4 +1,5 @@
{ coreutils
+, docopts
, fetchFromGitHub
, findutils
, gawk
@@ -23,8 +24,10 @@ stdenv.mkDerivation {
for bin in src/*.sh; do
cp $bin $out/share/$(basename $bin)
wrapProgram $out/share/$(basename $bin) \
+ --argv0 ''' \
--set PATH ${lib.makeBinPath [
coreutils
+ docopts
findutils
gawk
git
@@ -35,6 +38,6 @@ stdenv.mkDerivation {
tree-grepper
]}
done
- ln -s $out/share/extract.sh $out/bin/anissue
+ ln -s $out/share/anissue.sh $out/bin/anissue
'';
}
diff --git a/shell.nix b/shell.nix
index a85e845..bff07ad 100644
--- a/shell.nix
+++ b/shell.nix
@@ -7,6 +7,7 @@
pkgs.mkShell {
buildInputs = [
pkgs.coreutils
+ pkgs.docopts
pkgs.findutils
pkgs.gawk
pkgs.git
diff --git a/src/anissue.sh b/src/anissue.sh
new file mode 100755
index 0000000..10736c6
--- /dev/null
+++ b/src/anissue.sh
@@ -0,0 +1,45 @@
+#!/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.sh b/src/extract.sh
index 1e8440d..6422694 100755
--- a/src/extract.sh
+++ b/src/extract.sh
@@ -42,14 +42,6 @@
#
# @assigned kirchner@posteo.de
-# TODO Add command line modes list and show
-#
-# `anissue list` lists all issues in the current directory
-# `anissue show <issue>` shows an issue using it's id or automatically
-# assigned identifier
-#
-# @assigned aforemny
-
# TODO Generate and show hash for each issue
@@ -115,28 +107,4 @@ git ls-files --cached --exclude-standard --other |
"heading": $heading,
"start_row": $start_row
}'
- done | 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)
-
- 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