BASHing the Bible

Hello, readers. Before any of you get up in arms about the title of this post, relax, take a deep breath, and read on if you’re interested in inserting Scripture into documents, because that’s all this post is about.

The church I serve recently got a new laptop for my use (yay, thank you trustees!), and while it already had Windows 8 pre-installed, I carved out some space on the hard drive, and installed Linux, because that’s what I actually use.

So, that means a new installation for me. I *thought* I had transferred all of my favorite little tools and scripts that I put together from my old laptop, but apparently, I had forgotten a couple, including some BASH scripts that I used every single week in my sermon preparation. BASH means “Bourne Again SHell”, a scripting language for Linux and OSX (and yes, it’s also available on Windows). A script, for those of you who are Windows users, is like a batch file. You put a bunch of commands that you want run in sequence in it, and then just run that script. (Anyone remember AUTOEXEC.BAT?)

What I want to do is insert Scriptures into my text documents. How I’ve ended up doing this is by using a couple of tools, and chaining them together. This is done on an Ubuntu Linux system – your milage may vary. Frankly, I’m writing this post so that if I ever have to do this again, I won’t have to do it from scratch. Again.

Tools you’ll need:

  • diatheke – a command-line tool that uses the Crosswire Bible libraries. All of my Linux Bible programs are in this format, so this is what I use.
  • gtkdialog – a neat little tool that allows me to make fancy GUI front ends for scripts.
  • xclip – this command-line program allows me to specifically insert things from the command-line into the clipboard for use in GUI programs.

So, the workflow is this:

  1. Select the Bible references you want to use in your document.
  2. Tell the bible retrieval program (diatheke) which verses you want.
  3. Capture the results from the retrieval program in the clipboard.
  4. Paste the contents of the clipboard into your document.

If this seems a *lot* like ZipScript from the old WordSearch programs, you’ll know where I got the idea! Here’s the actual script itself.

#! /bin/bash

export MAIN_DIALOG='
<window title="Scripture Grab-O-Matic" icon-name="gtk-preferences" resizable="true" decorated="true" width_request="225">
 <vbox>
  <text><label>What NIV Scripture do you want?</label></text>
   <entry activates_default="true">
    <default>John 3:16</default>
     <variable>ENTRY</variable>
      <action>diatheke -b NIV -k $ENTRY | sed "s/^:.*//g" | sed "/^(NIV)/d" | xclip -selection c</action>	   
    </entry>
   <hbox>
    <button can-default="true" has-default="true" use-stock="true"></button>
   </hbox>
  </vbox>
</window>'

gtkdialog --program MAIN_DIALOG

UPDATE: in the middle of the action tag, there’s a couple of extra sed entries. These are placed here because diatheke keeps repeating the last line of whatever verses were requested. These sed commands remove the extra data, and the version label.

I don’t know if this will help anyone but me, but it’s a handy little script.

dialog box for Bible text

Scripture Grab-O-Matic dialog box

And here’s the code snippet that is inserted into Libreoffice. This simply calls a bash script to run. I made my script listed above executable, put it in my /usr/local/bin/ directory (where I put all my local stuff), and when I run the macro in Libreoffice, the bash script is launched.

Sub NIV
Shell "bash -c NIV"
End Sub
Advertisements

4 Responses to “BASHing the Bible”


  1. 1 Seth May 20, 2014 at 5:28 pm

    Thanks, Ed!
    I might set this up tomorrow on my Linux Lite and Xubuntu systems. This is very cool, actually.

  2. 2 pastoredb May 21, 2014 at 7:26 am

    Seth, if you’re interested, I can write a follow up post that shows how to tie this script to a toolbar button in LibreOffice.

  3. 3 Eric Bradshaw September 17, 2014 at 5:42 pm

    I’m writing to let you know of a free Christian operating system (a Linux-based one of course) and a computer ministry with a pretty unique way of sharing the good news. Computers4Christians takes in donated computers, wipes the hard drives, mixes and matches parts and loads them with the C4C Lubuntu ReSpin. We then give the computers away to whomever requests one in an area we serve (Cheyenne and Laramie WY for now). We’ve given away over 250 computers so far and we’re always hoping some like-minded Christian computer geeks will be interested in starting a chapter in their part of the world. And our Christian OS is free to download, easy to install via DVD or USB key and runs fast on most any computer manufactured in the last 10 years.

  4. 4 pastoredb September 18, 2014 at 9:44 am

    Thanks for the heads up, Eric. I’ve done that a few times myself – taken in old computers, fixed them up with Linux, and sent them out the door. Glad to know that others are doing the same!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Pastor Ed Backell

Flickr Photos

Pastoral Tweets

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 775 other followers


%d bloggers like this: