2020-04-20 18:56:08 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# bibel: 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] [reference...]"
|
|
|
|
echo
|
|
|
|
echo " -l list books"
|
|
|
|
echo " -W no line wrap"
|
2020-08-14 12:39:09 +02:00
|
|
|
echo " -F no footnotes"
|
2020-08-15 16:03:46 +02:00
|
|
|
echo " -h show help"
|
2020-04-20 18:56:08 +02:00
|
|
|
echo
|
|
|
|
echo " Reference types:"
|
|
|
|
echo " <Book>"
|
|
|
|
echo " Individual book"
|
|
|
|
echo " <Book>:<Chapter>"
|
|
|
|
echo " Individual chapter of a book"
|
|
|
|
echo " <Book>:<Chapter>:<Verse>[,<Verse>]..."
|
|
|
|
echo " Individual verse(s) of a specific chapter of a book"
|
|
|
|
echo " <Book>:<Chapter>-<Chapter>"
|
|
|
|
echo " Range of chapters in a book"
|
|
|
|
echo " <Book>:<Chapter>:<Verse>-<Verse>"
|
|
|
|
echo " Range of verses in a book chapter"
|
|
|
|
echo " <Book>:<Chapter>:<Verse>-<Chapter>:<Verse>"
|
|
|
|
echo " Range of chapters and verses in a book"
|
|
|
|
echo
|
|
|
|
echo " /<Search>"
|
|
|
|
echo " All verses that match a pattern"
|
|
|
|
echo " <Book>/<Search>"
|
|
|
|
echo " All verses in a book that match a pattern"
|
|
|
|
echo " <Book>:<Chapter>/<Search>"
|
|
|
|
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 bibel.tsv | awk -v cmd=list "$(get_data bibel.awk)"
|
|
|
|
exit
|
|
|
|
elif [ "$1" = "-W" ]; then
|
2020-04-25 21:09:24 +02:00
|
|
|
export BIBEL_NOLINEWRAP=1
|
2020-04-20 18:56:08 +02:00
|
|
|
shift
|
2020-08-14 12:39:09 +02:00
|
|
|
elif [ "$1" = "-F" ]; then
|
|
|
|
export BIBEL_NOFOOTNOTES=1
|
|
|
|
shift
|
2020-04-20 18:56:08 +02:00
|
|
|
elif [ "$1" = "-h" ] || [ "$isFlag" -eq 1 ]; then
|
|
|
|
show_help
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
cols=$(tput cols 2>/dev/null)
|
|
|
|
if [ $? -eq 0 ]; then
|
2020-04-25 21:09:24 +02:00
|
|
|
export BIBEL_MAX_WIDTH="$cols"
|
2020-04-20 18:56:08 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
if [ ! -t 0 ]; then
|
|
|
|
show_help
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Interactive mode
|
|
|
|
while true; do
|
|
|
|
printf "bibel> "
|
|
|
|
if ! read -r ref; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
get_data bibel.tsv | awk -v cmd=ref -v ref="$ref" "$(get_data bibel.awk)" | ${PAGER}
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
get_data bibel.tsv | awk -v cmd=ref -v ref="$*" "$(get_data bibel.awk)" | ${PAGER}
|