aboutsummaryrefslogtreecommitdiffstats
path: root/src/anissue.sh
blob: 10736c6a1584ac75734ceac1f0a9c82c03d43250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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