quran

English translation of the Quran from the command line
git clone https://riazj.com/git/quran
Log | Files | Refs | README | LICENSE

commit 810c289caf9f4c654def88bfe7adf957cc56f255
parent 4a0670f5b982c1879e2585a47b9c425c1e24f264
Author: Riaz <riaz@riazj.com>
Date:   Wed, 25 Jun 2025 14:24:39 -0700

Replace not_found() with error() and remove unneeded functions

Diffstat:
Mquran | 36++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/quran b/quran @@ -1,8 +1,8 @@ #!/bin/sh -e PREFIX="/usr/local/share/quran" -SURAHS="${PREFIX}/surahs.txt" -QURAN="${PREFIX}/quran.txt" +SURAHS="$PREFIX/surahs.txt" +QURAN="$PREFIX/quran.txt" case "$1" in -l) cat "$SURAHS"; exit ;; @@ -26,51 +26,43 @@ case "$1" in exit ;; esac -not_found() { - printf "quran: %s: %s not found\n" "$2" "$1" >&2; exit 1 -} - -check_for_invalid_range() { - [ "$2" -le "$3" ] || { printf "quran: %s-%s: invalid range of %s\n" "$2" "$3" "$1" >&2; exit 1; } -} - -show_surah_title() { - grep -A2 "^$surah\.\s" "$QURAN" +error() { + echo "quran: $1" >&2; exit 1 } get_surah_number() { surah="${1%:*}" - surah="$(grep -im1 "$surah" "$SURAHS")" || not_found "surah" "${1%:*}" + surah="$(grep -im1 "$surah" "$SURAHS")" || error "${1%:*}: surah not found" surah="${surah%%.*}" } read_ayah() { - show_surah_title && grep "\[$1\]" "$QURAN" || not_found "ayah" "$1" + grep "\[$1\]" "$QURAN" || error "$1: ayah not found" exit } read_ayat() { - start_ayah="${1#*:}" && start_ayah="${start_ayah%-*}" && end_ayah="${1#*-}" - show_surah_title && check_for_invalid_range "ayat" "$start_ayah" "$end_ayah" + start_ayah="${1#*:}"; start_ayah="${start_ayah%-*}"; end_ayah="${1#*-}" + [ "$start_ayah" -le "$end_ayah" ] || error "$start_ayah-$end_ayah: invalid range of ayat" while [ "$start_ayah" -le "$end_ayah" ]; do - grep "\[$surah:$start_ayah\]" "$QURAN" || not_found "ayah" "$surah:$start_ayah" + grep "\[$surah:$start_ayah\]" "$QURAN" || error "$surah:$start_ayah: ayah not found" start_ayah=$((start_ayah+1)) done exit } read_surah() { - grep -B3 "\[$1:" "$QURAN" || not_found "surah" "$1" + grep -B3 "\[$1:" "$QURAN" || error "$1: surah not found" exit } read_surahs() { - start_surah="$1" && end_surah="$2" - check_for_invalid_range "surahs" "$start_surah" "$end_surah" + start_surah="$1"; end_surah="$2" + [ "$start_surah" -le "$end_surah" ] || error "$start_surah-$end_surah: invalid range of surahs" while [ "$start_surah" -le "$end_surah" ]; do - grep -B3 -A1 "\[$start_surah:" "$QURAN" || not_found "surah" "$start_surah" + grep -B3 -A1 "\[$start_surah:" "$QURAN" || error "$start_surah: surah not found" start_surah=$((start_surah+1)) done exit @@ -101,4 +93,4 @@ echo "$1" | grep -q "^[[:alpha:]]\+-[[:alpha:]]\+$" && get_surah_number "${1#*-}" && end_surah=$surah && read_surahs "$start_surah" "$end_surah" -echo "quran: invalid command: see quran -h" >&2; exit 1 +error "invalid command: see quran -h"