From d7201d9f9aba12806fd13fbcfaeef3384dff81fc Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Wed, 30 Apr 2025 22:40:52 +1200 Subject: [PATCH 01/10] esvsearch: update inaccurate usage message --- esvsearch.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esvsearch.d b/esvsearch.d index e990d73..f65990e 100644 --- a/esvsearch.d +++ b/esvsearch.d @@ -71,7 +71,7 @@ main(string[] args) } if (args.length < 2) { - stderr.writefln("usage: %s [-e] [-l length] query", + stderr.writefln("usage: %s [-eV] [-c config] query", baseName(args[0])); return 1; } From e8da3e35cf343f0358ce389a094cea31e777336e Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 14:00:10 +1200 Subject: [PATCH 02/10] esv.1, esvsearch.1: add website URL --- esv.1 | 18 ++++++++++-------- esvsearch.1 | 14 ++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/esv.1 b/esv.1 index d8b58c1..305bdf9 100644 --- a/esv.1 +++ b/esv.1 @@ -1,4 +1,4 @@ -.Dd $Mdocdate: June 26 2024 $ +.Dd $Mdocdate: May 01 2025 $ .Dt ESV 1 .Os .Sh NAME @@ -143,12 +143,14 @@ Search the Bible for the phrase .Sh SEE ALSO .Xr esv.conf 5 .Sh AUTHORS -.An Jeremy Baxter Aq Mt jeremy@baxters.nz +.An Jeremy Baxter Aq Mt jeremy@reformers.dev +.Pp +Part of the +.Sy esv +distribution found at +.Lk https://reformers.dev/esv .Sh BUGS Currently there are no known bugs in -.Nm ; -but if you think you've found a potential bug, -please report it to me using my email address above. -.Pp -Existing bugs and planned features can be found on the bug tracker: -.Lk https://todo.sr.ht/~jeremy/esv +.Nm . +If you think you've found a potential bug, +please report it to my email address above. diff --git a/esvsearch.1 b/esvsearch.1 index c8a1046..c2a3c83 100644 --- a/esvsearch.1 +++ b/esvsearch.1 @@ -1,4 +1,4 @@ -.Dd $Mdocdate: June 26 2024 $ +.Dd $Mdocdate: May 01 2025 $ .Dt ESVSEARCH 1 .Os .Sh NAME @@ -55,7 +55,12 @@ Search the Bible for verses containing .Xr esv 1 , .Xr esv.conf 5 .Sh AUTHORS -.An Jeremy Baxter Aq Mt jeremy@baxters.nz +.An Jeremy Baxter Aq Mt jeremy@reformers.dev +.Pp +Part of the +.Sy esv +distribution found at +.Lk https://reformers.dev/esv .Sh BUGS .Nm outputs search results in a human-readable manner, @@ -66,7 +71,4 @@ should support outputting results in a shell-readable format and the JSON format. .Pp If you think you've found a potential bug, -please report it to me using my email address above. -.Pp -Existing bugs and planned features can be found on the bug tracker: -.Lk https://todo.sr.ht/~jeremy/esv +please report it to my email address above. From 94a954d6345310237219a3c18366345648b2e3ab Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 14:00:37 +1200 Subject: [PATCH 03/10] esvsearch.1: document -e option --- esvsearch.1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esvsearch.1 b/esvsearch.1 index c2a3c83..0b8ca4e 100644 --- a/esvsearch.1 +++ b/esvsearch.1 @@ -7,7 +7,7 @@ .Sh SYNOPSIS .Nm esvsearch .Bk -words -.Op Fl V +.Op Fl eV .Op Fl c Ar config .Ar query .Ek @@ -41,7 +41,10 @@ See the documentation on in .Xr esv 1 for more information. -.Sx ENVIRONMENT ) . +.It Fl e +Instead of showing loose matches for +.Ar query , +only show exact matches. .It Fl V Print the version number and exit. .El From 3d483fd0f46aa766710044384a6ec9d1d01fd556 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 14:41:00 +1200 Subject: [PATCH 04/10] esvapi: modify searchFormat() to take a function --- esvapi.d | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/esvapi.d b/esvapi.d index 78fa28c..fd6fb11 100644 --- a/esvapi.d +++ b/esvapi.d @@ -178,6 +178,12 @@ verseValid(in char[] verse) assert(verseValid("15:12-17")); } +string +defaultSearchFmt(string reference, string content) pure +{ + return format!"\033[1m%s\033[0m\n %s\n"(reference, content.wrap(80)); +} + /++ + Structure containing the authentication key, API URL, + any parameters to use when making a request as well as the @@ -319,11 +325,12 @@ struct ESVApi } /++ - + Calls search() and formats the results nicely as plain text. + + Calls search() and formats the results nicely as plain text, + + unless a custom function is provided. +/ string - searchFormat(alias fmt = "\033[1m%s\033[0m\n %s\n") - (in string query, int lineLength = 0) /* 0 means default */ + searchFormat(in string query, + string function(string, string) fmt = &defaultSearchFmt) { char[] layout; JSONValue resp; @@ -334,15 +341,9 @@ struct ESVApi enforce!ESVException(resp["total"].integer != 0, "No results for search"); - lineLength = lineLength == 0 ? 80 : lineLength; - () @trusted { foreach (JSONValue item; resp["results"].array) { - layout ~= format!fmt( - item["reference"].str, - item["content"].str - .wrap(lineLength) - ); + layout ~= fmt(item["reference"].str, item["content"].str); } }(); From 4564b88e4254d436f5386d3839e6891034dd015a Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 19:12:40 +1200 Subject: [PATCH 05/10] esvapi: rename ESVAPI_PARAMETERS to esvapiParameters Keep with D code style --- esvapi.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esvapi.d b/esvapi.d index fd6fb11..aa3f05a 100644 --- a/esvapi.d +++ b/esvapi.d @@ -114,7 +114,7 @@ immutable string[] bibleBooks = [ ]; /++ All allowed API parameters (for text passages). +/ -immutable string[] ESVAPI_PARAMETERS = [ +immutable string[] esvapiParameters = [ "include-passage-references", "include-verse-numbers", "include-first-verse-numbers", From 67171b71dc71043004215898d2b306dc8760a3c9 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 19:36:02 +1200 Subject: [PATCH 06/10] esvsearch: implement machine-readable output format --- esvsearch.d | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/esvsearch.d b/esvsearch.d index f65990e..c070a9b 100644 --- a/esvsearch.d +++ b/esvsearch.d @@ -24,7 +24,9 @@ import std.file : FileException; import std.getopt : getopt, GetOptException; import std.path : baseName, expandTilde; import std.process : environment; +import std.regex : regex, matchAll, replaceFirst; import std.stdio : writeln, writefln; +import std.string : tr; import esvapi; import initial; @@ -36,8 +38,28 @@ import cf = config; string cFlag; /* config path */ bool eFlag; /* exact matches */ +bool mFlag; /* machine readable */ bool VFlag; /* show version */ +string +machineReadableFmt(string reference, string content) +{ + /* match the start of the reference against bibleBooks + * to identify what book it's from, so we can replace + * spaces in the book name with underscores :-) */ + foreach (string book; bibleBooks) { + auto match = reference.matchAll(regex("^(" ~ book ~ ") \\d")); + if (!match.empty) { + assert(match.captures[1] == book + && bookValid(match.captures[1])); + reference = reference.replaceFirst( + regex('^' ~ book), book.tr(" ", "_")); + } + } + + return reference ~ " / " ~ content ~ "\n"; +} + int main(string[] args) { @@ -59,6 +81,7 @@ main(string[] args) config.caseSensitive, "c", &cFlag, "e", &eFlag, + "m", &mFlag, "V", &VFlag, ); } catch (GetOptException e) { @@ -71,7 +94,7 @@ main(string[] args) } if (args.length < 2) { - stderr.writefln("usage: %s [-eV] [-c config] query", + stderr.writefln("usage: %s [-emV] [-c config] query", baseName(args[0])); return 1; } @@ -110,7 +133,9 @@ main(string[] args) } try - writeln(esv.searchFormat(query)); + writeln(mFlag + ? esv.searchFormat(query, &machineReadableFmt) + : esv.searchFormat(query)); catch (ESVException) die("no results"); catch (CurlException e) From bc342d0415c05f81670467fed7b3922ee5669d92 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 19:42:57 +1200 Subject: [PATCH 07/10] esvsearch.1: document -m --- esvsearch.1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/esvsearch.1 b/esvsearch.1 index 0b8ca4e..50bf4b0 100644 --- a/esvsearch.1 +++ b/esvsearch.1 @@ -7,7 +7,7 @@ .Sh SYNOPSIS .Nm esvsearch .Bk -words -.Op Fl eV +.Op Fl emV .Op Fl c Ar config .Ar query .Ek @@ -45,6 +45,12 @@ for more information. Instead of showing loose matches for .Ar query , only show exact matches. +.It Fl m +Print matches in a machine-readable format, +where each result takes up just one line. +Any spaces in the book name are replaced with underscores +and a slash character separates the passage reference +from the passage content. .It Fl V Print the version number and exit. .El @@ -65,13 +71,7 @@ Part of the distribution found at .Lk https://reformers.dev/esv .Sh BUGS -.Nm -outputs search results in a human-readable manner, -which makes it nice for humans to read but difficult -for machines to parse and store. -.Nm -should support outputting results in a shell-readable format -and the JSON format. -.Pp +Currently there are no known bugs in +.Nm . If you think you've found a potential bug, please report it to my email address above. From 5c366d64b0bf2f78e235d5aaa1f6d02a8af08422 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 20:00:24 +1200 Subject: [PATCH 08/10] esv.1: revise --- esv.1 | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/esv.1 b/esv.1 index 305bdf9..30c5a51 100644 --- a/esv.1 +++ b/esv.1 @@ -15,8 +15,7 @@ .Sh DESCRIPTION .Nm displays Bible passages on your terminal. -It can also play recorded audio tracks of certain passages, -through integration with an MP3 player utility. +It can also play audio passages. .Pp See the section .Sx EXAMPLES @@ -27,29 +26,28 @@ Verses can be provided in the format of .Em chapter:verse , and .Em chapter:verse-verse . -If the name of your desired book has a space in it, e.g. +If the name of your desired book has spaces in it, e.g. .Dq "1 Corinthians" , -you can put a hyphen or underscore in the place of the space, -or you can just pass the full book name with the space in it -by surrounding the argument with quotes in your shell. +you can provide the book name with hyphens or underscores in place of +the spaces, or you can pass the original book name. Thus, both .Dq 1-Corinthians and -.Dq "1 Corinthians" -are valid book names. +.Dq 1_Corinthians +are also valid book names. .Pp By default, .Xr mpg123 1 -is used as the MP3 player. -However, this can be overridden; +is used as the player for audio passages. +This can be overridden however; see the .Sx ENVIRONMENT -section for more information on this. +section for more information. .Pp The options are as follows: .Bl -tag -width 123456 .It Fl a -Play a recorded audio track rather than showing a passage. +Play an audio passage instead of printing a text passage. .It Fl c Ar config Read the configuration from the path .Ar config . @@ -114,7 +112,8 @@ Where to read the configuration file, rather than using the default location (see section .Sx FILES ) . .It Ev ESV_PLAYER -The name of the MP3 player to use for playing audio passages. +The name of the audio player to use when playing audio passages. +The program specified must support playing MP3 audio. If this is not set, .Nm will look for @@ -133,14 +132,10 @@ Read John 1:29-31: .Pp Listen to a recorded audio track of Psalm 128: .Pp -.Dl esv -a Psalm 128 -.Pp -Search the Bible for the phrase -.Dq "in love" : -.Pp -.Dl esv -s 'in love' +.Dl esv -a Psalm 139 .Pp .Sh SEE ALSO +.Xr esvsearch 1 .Xr esv.conf 5 .Sh AUTHORS .An Jeremy Baxter Aq Mt jeremy@reformers.dev From 0b2133bae2050d99f86232a439de9af982994ec7 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 20:07:35 +1200 Subject: [PATCH 09/10] esv.conf.5: revise --- esv.conf.5 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/esv.conf.5 b/esv.conf.5 index 34164c3..0612b8d 100644 --- a/esv.conf.5 +++ b/esv.conf.5 @@ -1,4 +1,4 @@ -.Dd $Mdocdate: March 23 2023 $ +.Dd $Mdocdate: May 01 2025 $ .Dt ESV.CONF 5 .Os .Sh NAME @@ -15,9 +15,12 @@ An example is listed below: .Dl [section] .Dl key = value .Pp -Comments can be used by putting a hashtag +A line beginning with a hashtag .Dq # -symbol at the beginning of a line. +will be considered a +.Dq comment +and will be ignored by +.Xr esv 1 . .Pp The available configuration options are as follows: .Bl -tag -width keyword From 1136fa01bbcf469f62b5b97ddd59def9aae587a3 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 1 May 2025 20:09:59 +1200 Subject: [PATCH 10/10] esv-0.3.0 --- README | 2 +- config.di | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index c92b8b7..1429a8d 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is esv, a program that displays Bible passages on the terminal. +This is esv 0.3.0, a program that displays Bible passages on the terminal. To build, first install the LDC compiler and libcurl. Configure the build environment, compile and optionally install: diff --git a/config.di b/config.di index 041e561..5a15fdc 100644 --- a/config.di +++ b/config.di @@ -2,7 +2,7 @@ module config; public: -enum esvVersion = "0.2.0-dev"; +enum esvVersion = "0.3.0"; enum apiKey = "abfb7456fa52ec4292c79e435890cfa3df14dc2b"; enum configPath = "~/.config/esv.conf";