vul

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

vul.sh (2210B)


      1 #!/bin/sh
      2 # vul: Read the Word of God in Greek from your terminal
      3 # License: Public domain
      4 
      5 SELF="$0"
      6 
      7 get_data() {
      8 	sed '1,/^#EOF$/d' < "$SELF" | tar xz -O "$1"
      9 }
     10 
     11 if [ -z "$PAGER" ]; then
     12 	if command -v less >/dev/null; then
     13 		PAGER="less"
     14 	else
     15 		PAGER="cat"
     16 	fi
     17 fi
     18 
     19 show_help() {
     20 	exec >&2
     21 	echo "usage: $(basename "$0") [flags] [reference...]"
     22 	echo
     23 	echo "  -l      list books"
     24 	echo "  -W      no line wrap"
     25 	echo "  -h      show help"
     26 	echo
     27 	echo "  Reference types:"
     28 	echo "      <Book>"
     29 	echo "          Individual book"
     30 	echo "      <Book>:<Chapter>"
     31 	echo "          Individual chapter of a book"
     32 	echo "      <Book>:<Chapter>:<Verse>[,<Verse>]..."
     33 	echo "          Individual verse(s) of a specific chapter of a book"
     34 	echo "      <Book>:<Chapter>-<Chapter>"
     35 	echo "          Range of chapters in a book"
     36 	echo "      <Book>:<Chapter>:<Verse>-<Verse>"
     37 	echo "          Range of verses in a book chapter"
     38 	echo "      <Book>:<Chapter>:<Verse>-<Chapter>:<Verse>"
     39 	echo "          Range of chapters and verses in a book"
     40 	echo
     41 	echo "      /<Search>"
     42 	echo "          All verses that match a pattern"
     43 	echo "      <Book>/<Search>"
     44 	echo "          All verses in a book that match a pattern"
     45 	echo "      <Book>:<Chapter>/<Search>"
     46 	echo "          All verses in a chapter of a book that match a pattern"
     47 	exit 2
     48 }
     49 
     50 while [ $# -gt 0 ]; do
     51 	isFlag=0
     52 	firstChar="${1%"${1#?}"}"
     53 	if [ "$firstChar" = "-" ]; then
     54 		isFlag=1
     55 	fi
     56 
     57 	if [ "$1" = "--" ]; then
     58 		shift
     59 		break
     60 	elif [ "$1" = "-l" ]; then
     61 		# List all book names with their abbreviations
     62 		get_data vul.tsv | awk -v cmd=list "$(get_data vul.awk)"
     63 		exit
     64 	elif [ "$1" = "-W" ]; then
     65 		export KJV_NOLINEWRAP=1
     66 		shift
     67 	elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
     68 		show_help
     69 	else
     70 		break
     71 	fi
     72 done
     73 
     74 cols=$(tput cols 2>/dev/null)
     75 if [ $? -eq 0 ]; then
     76 	export KJV_MAX_WIDTH="$cols"
     77 fi
     78 
     79 if [ $# -eq 0 ]; then
     80 	if [ ! -t 0 ]; then
     81 		show_help
     82 	fi
     83 
     84 	# Interactive mode
     85 	while true; do
     86 		printf "vul> "
     87 		if ! read -r ref; then
     88 			break
     89 		fi
     90 		get_data vul.tsv | awk -v cmd=ref -v ref="$ref" "$(get_data vul.awk)" | ${PAGER}
     91 	done
     92 	exit 0
     93 fi
     94 
     95 get_data vul.tsv 2>/dev/null | awk -v cmd=ref -v ref="$*" "$(get_data vul.awk)" 2>/dev/null | ${PAGER}