#!/bin/bash
#
VERSION=0.2.8
#
# Textus Scriptus the modified and improved CLI Bible interface version 0.2.8
# i reworked the way ts identifies whether or not it is in irc mode i also
# altered a grep switch, added the -m but it is not supported in some early
# grep versions. so it will error out if your grep is too old .
# in 0.2.7 i also tinkered with the colouring a bit and reformated the whole
# script. in 0.2.8 i added the -d switch and fixed a bug in the colours.
# not all features are 100% backwards compatable but -r should work back
# several versions anyway.
#
#
# bibles are in plain text formated one verse per line with the headings,
# +book #:#+ verse text here. where # is chapter number and verse num.
# see who owns us so we know how to act.
if [ $(ps -ax | grep $PPID | grep -c xchat)0 -gt 9 ] ;then
SHELL="IRC" ;
elif [ $(ps -ax | grep $PPID | grep -c BitchX)0 -gt 9 ] ;then
SHELL="IRC" ;
elif [ $(ps $PPID | grep -c bash)0 -gt 9 ] ;then
SHELL="BASH" ;
elif [ $(ps $PPID | grep -c sh)0 -gt 9 ] ;then
SHELL="SHELL";
else
SHELL="IRC" ;
fi
# set the terminal/console size for formating text so we don't split words
if [ $SHELL = BASH ] ;then
LINES="$(stty -a | grep -ie"columns" | cut -c 24,25)" ;
if [ $(stty -a | grep -ie"columns" | cut -c 36,37) -gt 25 ] ;then
COLUMNS="$(stty -a | grep -ie"columns" | cut -c 36,37)" ;
else
COLUMNS="$(stty -a | grep -ie"columns" | cut -c 36,37,38)" ;
fi ;
elif [ $SHELL = SHELL ] ;then
LINES="$(stty -a | grep -ie"columns" | cut -c 24,25)" ;
if [ $(stty -a | grep -ie"columns" | cut -c 36,37) -gt 25 ] ;then
COLUMNS="$(gawk -v CONVFMT="%12.2f" -v OFMT="%.9g" "BEGIN { print $(stty -a | grep -ie"columns" | cut -c 36,37) - 2 ; }";)" ;# "
else
COLUMNS="gawk -v CONVFMT="%12.2f" -v OFMT="%.9g" "BEGIN { print $(stty
-a | grep -ie"columns" | cut -c 36,37,38) - 2 ; }";# "
fi ;
else
COLUMNS="999" ;
LINES="99" ;
fi
# get a translation name from our own name symlink access makes this work
if [ x != x$(echo $0 | cut -d / -f 5 ) ] ;then
TRANS="$(echo $0 | cut -d / -f 5 )" ;
elif [ x != x$(echo $0 | cut -d / -f 4 ) ] ;then
TRANS="$(echo $0 | cut -d / -f 4 )" ;
elif [ x != x$(echo $0 | cut -d / -f 3 ) ] ;then
TRANS="$(echo $0 | cut -d / -f 3 )" ;
elif [ x != x$(echo $0 | cut -d / -f 2 ) ] ;then
TRANS="$(echo $0 | cut -d / -f 2 )" ;
else
TRANS="$(echo $0)" ;
fi
# supply a default just in case.
if [ $TRANS = ts ] ;then
export TRANS='kjv' ;
fi
# do we have a book to read ?
if [ -f "$(echo ~)/Documents/bibles/bible.$TRANS" ] ;then
export PREFIX="$(echo ~)/Documents/bibles" ;
else
echo "$(if [ $(echo $0 | cut -d/ -f5)x != x ] ;then echo "$0" | cut -d/ -f5
;else echo "$0" | cut -d/ -f4 ;fi )" ;exit 2 ;
fi
# the actual work starts here, the environment is now set so we can start with
# if we are in an irc window we use anti flooding measures other wise less
if [ $SHELL = BASH ] ;then
# -h help cry, we always answer a cry for help.
if [ x$1 = x-h ] ;then
$0 --help ;exit 1
# --help gnu style help cry, we always answer a cry for help.
elif [ x$1 = x--help ] ;then
echo "
ts 'text search' version $VERSION
syntax; $PS1 <ext> -[a.c,e,f,l,r,x] <string or words>
ts version $VERSION is a simple bash script that searchs through
$PREFIX/bible.<ext> file
and displays the matching text. Word searchs are supported in several
formats/methods. as well as verse refferance listings. exanples are
given for all types.
single switchs only. dont combine -* -* nor -** it wont work right.
and the dash - is required for all switchs. see below !
all examples are enclosed in parentheses marks --> ( )
no switch default mode: phrase or refferance,
a phrase search like this.
example; ( $0 follow me )
will yeld large results in some cases, so think before you type.
a verse refferance would be a dirrect refferance like this.
example; ( $0 Matthew 11:15 )
-a all words, will recursively search for the words until it finds
all the lines(n) that contain each of the words listed.(any order)
example; ( $0 -a Jesus moses peter )
displays; Matthew 17:4 + Mark 9:5 + Luke 9:33 because all
the words are found in those verses only.
-c just count and dont show. counts places <input> appears
example; ( $0 -c Nicodemus )
renders the number 5, because that's in how many times it counted.
-d display a list of the verses that match the search string
example; ( $0 -d Nicodemus )
renders the 5 verses that the -c search above counted.
-e every word, will list the referances of all words, each sepratly.
this can be very long because each occurance of each word shows.
example; ( $0 -e Nicodemus leviathan jasper )
this will hit books from exodus job psalms revelation isaiah ...
even though you wouldn't think those three words so popular.
-f first show only the first verse that contain the search phrase.
example; ( $0 -f evil for good )
shows Genesis 44:4 the first place its found.
-l last shows the last place the phrase is found in the Bible.
example; ( $0 -l evil for good )
returns Proverbs 17:13 the last place its found.
-r regular expression, the way you type a string is the way it must
appear in the text file. (except case)
example; ( $0 -r lovest thou me )
although it display the verses and context.
the. -r can be used for a verse search like
example; ( $0 -r john 21:16 )
also good for reading a chapter or even a whole book like this,
example; ( $0 -r 1 John 3 )
or; ( $0 -r 2 John )
-x check to see if a word is in the Bible. check only !
example; ( $0 -x faith )
will display the word 'faith exists in bible.$TRANS' because it is.
example; ( $0 -x linux )
will display 'phrase is not in bible.$TRANS' because it wasn't found.
(notes) if no -# argument is entered the search is a default search and must
be in the form of a book chapter and verse 'john 3:16' or a dirrect
quote from the Bible, [ notice that for irc use, i've tried to make
it NOT flood a channel if you goof, but be careful anyway ]
All searches are piped to less if in a bash or sh shell and if there
are more than $LINES lines of text to display,
[ the number of lines on this terminal ]. and are case insensitive.
the -a (all words search) and the -e (every word search) are
quite different, VERY DIFFERENT ! try them and see.
if you search has a parenthesis mark you must dubble quote it.
example; ( $0 $(echo '"(then saith he"') )
Symbolic links are used to tell ts which translation to search in.
such as (kjv john 3:16) for the king james 'authorized' translation.
after you install a new bible just make a link to 'ts' with the new
extention as the name.
Example; ( ln -s /<path>/ts /<path>/nas )
for the new american standard translation. --> [ bible.nas ]
you should make sure that there is not already a command named 'nas'.
be sure to install to the correct path, or alter the portion of this
script that deals with paths and sets the $(echo '$PREFIX') veriable.
ts-$VERSION --requires; bash=2.0+ grep=2.5+ echo=3+ less=any textutils=2.1+"# -a all words, will recursively search for the words
elif [ x$1 = x-a ] ;then
if [ -f $PREFIX/bible.$TRANS ] ;then shift ;
export TIMES=1 ;
grep -i $1 $PREFIX/bible.$TRANS > ~/tmp/burdened$TIMES ;
while [ x$1 != x ] ;do
grep -i $1 ~/tmp/burdened$TIMES > ~/tmp/burdened$(gawk -v CONVFMT="%12.2f" -v OFMT="%.9g" "BEGIN { print $TIMES + 1 ; }";) ;
export TIMES="$(gawk -v CONVFMT="%12.2f" -v OFMT="%.9g" "BEGIN
{ print $TIMES + 1 ; }";)" ;
shift ;
done ;
if [ $(cat ~/tmp/burdened$TIMES | fold -sw $COLUMNS | wc -l ) -gt $(gawk -v CONVFMT="%12.2f" -v OFMT="%.9g" "BEGIN { print $LINES - 2 ; }";) ] ;then
cat ~/tmp/burdened$TIMES | fold -sw $COLUMNS | less ;
else
cat ~/tmp/burdened$TIMES | fold -sw $COLUMNS | sed s/"+.*+"/"$(printf "\033[1;31m&")$(printf "\033[1;000m")"/ ;
fi ;
rm -f ~/tmp/burdened* ;
fi
# -c just count and dont show.
elif [ x$1 = x-c ] ;then shift ;
echo "found $* in the -- $(printf "\033[1;32m$TRANS")$(printf "\033[1;000m") -- $(grep -c -i -e "$*" $PREFIX/bible.$TRANS) times "
# -d display a list of the verses that match the search string
elif [ x$1 = x-d ] ;then shift ;
if [ $(grep -hie "$*" $PREFIX/bible.$TRANS | cut -b"-$COLUMNS" | wc -l ) -gt $LINES ] ;then
echo "$(grep -hie "$*" $PREFIX/bible.$TRANS)" | sed s/"$*"/"__$*__"/ | cut -b"-$COLUMNS" | less ;
else
if [ $(grep -i -h -e "$*" $PREFIX/bible.$TRANS | cut -b"-$COLUMNS"
| wc -l )0 -gt 9 ] ;then
echo "$(grep -i -h -e "$*" $PREFIX/bible.$TRANS)" | cut -b"-$COLUMNS" | sed s/"$*"/"$(printf "\033[1;36m$*")$(printf "\033[1;000m")"/ | sed s/"+.*+"/"$(printf "\033[1;31m&")$(printf "\033[1;000m")"/ ;
fi;
fi
# -e every word, will list the referances of all words, each sepratly.
elif [ x$1 = x-e ] ;then shift ;
rm -f ~/tmp/flexable ;
if [ -e ~/tmp/flexable ] ;then
echo "echo -- $(printf "\033[1;32m$TRANS")$(printf "\033[1;000m") -- ERROR; $UNAME does not own ~/tmp/flexable ! please delete it." ;exit 99 ;
fi ;
for TEMP in $* ;do
grep -i -h -w $TEMP $PREFIX/bible.$TRANS >> ~/tmp/flexable ;
done ;
if [ -s ~/tmp/flexable ] ;then
if [ 1$(cat ~/tmp/flexable | fold -s -w $COLUMNS | wc -l) -gt 1$LINES ] ;then
echo "$(cat ~/tmp/flexable | fold -s -w $COLUMNS | less) ";
else
echo "$(cat ~/tmp/flexable | fold -s -w $COLUMNS) ";
fi;
fi
# -f first show only the first verse that contain the search phrase.
elif [ x$1 = x-f ] ;then shift ;
grep -i -m 1 -h -e "$*" $PREFIX/bible.$TRANS | fold -s -w $COLUMNS | sed s/"$*"/"$(printf "\033[1;36m$*")$(printf "\033[1;000m")"/
# -l last shows the last place the phrase is found in the Bible.
elif [ x$1 = x-l ] ;then shift ;
echo -- $(printf "\033[1;32m$TRANS")$(printf "\033[1;000m") -- $(tac $PREFIX/bible.$TRANS | grep -i -m 1 -h -e "$*") | fold -s -w $COLUMNS | sed s/"$*"/"$(printf "\033[1;36m$*")$(printf "\033[1;000m")"/
# -r regular expression,
elif [ x$1 = x-r ] ;then shift ;
if [ $(grep -i -h -e "$*" $PREFIX/bible.$TRANS | fold -s -w $COLUMNS | wc -l ) -gt $LINES ] ;then
echo "$(grep -i -h -e "$*" $PREFIX/bible.$TRANS)" | sed s/"$*"/"__$*__"/ | fold -s -w $COLUMNS | less ;
else
if [ $(grep -i -h -e "$*" $PREFIX/bible.$TRANS | fold -s -w $COLUMNS | wc -l )0 -gt 9 ] ;then
echo "$(grep -i -h -e "$*" $PREFIX/bible.$TRANS) -- $(printf "\033[1;32m$TRANS")$(printf "\033[1;000m") --" | fold -s -w $COLUMNS | sed s/"$*"/"$(printf "\033[1;36m$*")$(printf "\033[1;000m")"/ | sed s/"+.*+"/"$(printf "\033[1;31m&")$(printf "\033[1;000m")"/ ;
fi;
fi
# -v version
elif [ x$1 = x-v ] ;then
echo "$(printf "\033[1;36m$0")$(printf "\033[1;000m") -> 'ts' text_search, version $VERSION"
# -x check to see if a word is in the Bible. check only !
elif [ x$1 = x-x ] ;then shift ;
if [ $(grep -i -w -m 1 -e "$*" $PREFIX/bible.$TRANS | wc -l )0 -gt 9 ] ;then
echo " yes, \"$(printf "\033[1;36m$*")$(printf "\033[1;000m")\" was
found in the $(printf "\033[1;36m$TRANS")$(printf "\033[1;000m") " ;
elif [ $(grep -m 1 -i -e "$*" $PREFIX/bible.$TRANS | wc -l)0 -gt 9 ] ;then
echo "sorry, \" $(printf "\033[1;31m$*")$(printf "\033[1;000m ")\" is not in $PREFIX/bible.$TRANS ! ispell sujests, \" $(echo "$*" | ispell
| grep -v Ispell | grep -m 1 [a-z] ) \" ?" ;
else
echo "sorry, \" $(printf "\033[1;31m$*")$(printf "\033[1;000m ")\" is not in $PREFIX/bible.$TRANS !" ;
fi
# no arg. no exp. open the bible with less
elif [ x$1 = x ] ;then
echo "$(fold -s -w $COLUMNS $PREFIX/bible.$TRANS) --$TRANS--"| less
# exp. search for reg. exp. could be a refferance or string search
else
if [ $(echo $1 | grep -c -e - )0 -gt 9 ] ;then
echo "unknown agrument try ts --help" ;exit 3 ;
else
if [ $(grep -i -w -h -e "$*" $PREFIX/bible.$TRANS | fold -s -w
$COLUMNS | wc -l ) -gt $LINES ] ;then
echo "$(grep -w -i -h -e "$*" $PREFIX/bible.$TRANS) --$TRANS--" | sed s/"$*"/"_$*_"/ | fold -s -w $COLUMNS | less ;
else
echo "$(grep -w -i -h -e "$*" $PREFIX/bible.$TRANS) --$(printf "\033[1;32m$TRANS")$(printf "\033[1;000m")--" | fold -s -w $COLUMNS | sed s/"$*"/"$(printf "\033[1;36m$*")$(printf "\033[1;000m")"/ | sed s/"+.*+"/"$(printf
"\033[1;31m&")$(printf "\033[1;000m")"/ ;
fi;
fi
fi
# irc mode *** anti-flooding measures may not always work, use with caution !
else
if [ $(grep -s -i -h -w -e "+$*+" $PREFIX/bible.$TRANS | wc -l )0 -gt 9 ] ;then
echo "$TRANS $(grep -i -w -e "+$*+" $PREFIX/bible.$TRANS)" ;
elif [ x$1 = x-r ] ;then shift ;
if [ $(grep -w -i -h -e "$*" $PREFIX/bible.$TRANS | wc -l ) -gt $LINES ] ;then
if [ -e long-irc.$TRANS ] ;then
rm -f long-irc.$TRANS ;
echo "$TRANS$(grep -m $LINES -w -i -h -e "$*" $PREFIX/bible.$TRANS) -- $TRANS --" ;
else
touch long-irc.$TRANS ;
echo "returns too many matches. send again to paste only the first 7" ;
fi ;
else
echo "$(grep -w -i -h -e "$*" $PREFIX/bible.$TRANS) -- $TRANS --" ;
fi ;
else
echo "sorry; not in irc, try: $TRANS [-r] <string_or_reference>" ;exit 3 ;
fi
fi
# that's all folks.