#!/bin/sh # kjv: Read the Word of God from your terminal # License: Public domain SELF="$0" get_data() { sed '1,/^#EOF$/d' < "$SELF" | tar xz -O "$1" } if [ -z "$PAGER" ]; then if command -v less >/dev/null; then PAGER="less" else PAGER="cat" fi fi show_help() { exec >&2 echo "usage: $(basename "$0") [flags] " echo echo " -l list books" echo " -W no line wrap" echo " -h show help" echo echo " References types:" echo " " echo " Individual book" echo " :" echo " Individual chapter of a book" echo " ::[,]..." echo " Individual verse(s) of a specific chapter of a book" echo " :-" echo " Range of chapters in a book" echo " ::-" echo " Range of verses in a book chapter" echo " ::-:" echo " Range of chapters and verses in a book" echo echo " /" echo " All verses that match a pattern" echo " /" echo " All verses in a book that match a pattern" echo " :/" echo " All verses in a chapter of a book that match a pattern" exit 2 } while [ $# -gt 0 ]; do isFlag=0 firstChar="${1%"${1#?}"}" if [ "$firstChar" = "-" ]; then isFlag=1 fi if [ "$1" = "--" ]; then shift break elif [ "$1" = "-l" ]; then # List all book names with their abbreviations get_data kjv.tsv | awk -v cmd=list "$(get_data kjv.awk)" exit elif [ "$1" = "-W" ]; then export KJV_NOLINEWRAP=1 shift elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then show_help else break fi done if [ $# -eq 0 ]; then show_help fi startIdx=$# (while [ $# -gt 0 ]; do if [ "${startIdx}" -ne $# ]; then echo fi get_data kjv.tsv | awk -v cmd=ref -v ref="$1" "$(get_data kjv.awk)" shift done ) | ${PAGER}