diff --git a/README.md b/README.md index e1e68d1..6a63723 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -## HOW TO USE THIS SCRIPT +# HOW TO USE THIS SCRIPT -**You can call it directly with a query like this:** +### You can call it directly with a query like this ```bash -/bin/bash <(/bin/curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" +bash <(curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" ``` Will return: ```text @@ -13,10 +13,10 @@ Will return: ``` > each verse per line, with the line number as the first value in the line. -**Other translations, use as a second argument the abbreviation of the translation.** +### Other translations, use as a second argument the abbreviation of the translation. ```bash -/bin/bash <(/bin/curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" textusreceptus +bash <(curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" textusreceptus ``` Will return: ``` @@ -27,7 +27,7 @@ Will return: > each verse per line, with the line number as the first value in the line. ```bash -/bin/bash <(/bin/curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" korean +bash <(curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "John 3:16-18" korean ``` Will return: ``` @@ -49,7 +49,23 @@ https://getbible.net/v2/aov/books.json Here is a list of [translations](https://github.com/getbible/v2/blob/master/translations.json) available. -#### Todo +### You are able to also make queries with the book number like this + +```bash +bash <(curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/chapter.sh) "43 3:16-18" +``` + +### You are able to also make queries with the book number to get its name like this + +```bash +bash <(curl -s https://raw.githubusercontent.com/getbible/getverse/master/src/name.sh) "43 3:16-18" +``` +Will return: +``` +John 3:16-18 +``` + +### Todo - validate queries - Increase the various ways to query verses diff --git a/src/name.sh b/src/name.sh new file mode 100755 index 0000000..15936a3 --- /dev/null +++ b/src/name.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Do some prep work +command -v jq >/dev/null 2>&1 || { + echo >&2 "We require jq for this script to run, but it's not installed. Aborting." + exit 1 +} +command -v curl >/dev/null 2>&1 || { + echo >&2 "We require curl for this script to run, but it's not installed. Aborting." + exit 1 +} +# set the query (default: 1 John 3:16-18) +QUERY="${1:-62 3:16-18}" +# set the translation (default: kjv) +VERSION="${2:-kjv}" +# get the name from the query TODO: find better filter +BOOKNAME=$(echo ${QUERY%%[0-9]?:*} | xargs echo -n) +BOOKNAME=$(echo ${BOOKNAME%%[0-9]:*} | xargs echo -n) +# check if the name was given by number +re='^[0-9]+$' +if [[ "$BOOKNAME" =~ $re ]]; then + # get the list of books from the API to get the book number + BOOKS=$(curl -s "https://getbible.net/v2/${VERSION}/books.json") + BOOK_NAME=$(echo "$BOOKS" | jq -r ".[] | select(.nr == ${BOOKNAME}) | .name") + # get chapter and verses numbers + NUMBERS=$(echo "${QUERY/$BOOKNAME/}" | xargs echo -n) + # get chapter and verses numbers + echo "${BOOK_NAME} ${NUMBERS}" +else + echo "$QUERY" +fi + +exit 0