#! /usr/bin/env sh exec guile -e main -s "$0" "$@" !# (use-modules (bible-tools bible-tools) (srfi srfi-1) (srfi srfi-26)) (define (search phrase txt) (let ((rx (make-regexp phrase regexp/icase))) (filter (lambda (v) (regexp-exec rx (text v))) txt))) (define (help) (display "Usage: search-bible search-phrase [-b book] [-c chapter]") (display " [-h] [-v] [--bible b]\n") (display "\t-b book search in this book\n") (display "\t-c chapter search in this chapter\n") (display "\t-h display this help message\n") (display "\t-v display the current version\n") (display "\t--bible b use this bible\n")) (define (main args) (define (pr t) (map (lambda (str) (display str) (newline)) (map verse->string (search (cadr args) t)))) (define version "search-bible v1.0.0\n") (define flag? (cut member <> args)) (define get (compose cadr flag?)) (let-syntax ((conf (syntax-rules (else) ((_ (f e)... (else g)) (cond ((flag? f) e)... (else g)))))) (let ((bible (if (flag? "--bible") (get "--bible") "elb1871"))) (with-bible bible (conf ("-h" (help)) ("-v" (display version)) ("-b" (if (flag? "-c") (call-with-chapter (get "-b") (get "-c") pr) (call-with-book (get "-b") pr))) (else (if (< 1 (length args)) pr (help))))))))