Summary

I add a tmux-splitting vipe-like command for replacing the selected text with a matching Bible verse.

Matthew 3
And think not to say within yourselves, We have Abraham to our father: for I say unto you, that God is able of these stones to raise up children unto Abraham.

Demo

Filter command

1
tvipify "semantic-bible-search -oc"   # Look up a bible verse based on the selection, and replace the selection with the org link

Scripts

tvipify

1
2
3
4
5
6
7
8
#!/bin/bash
export TTY

vipe_cmd="$1"
# eipe
: "${vipe_cmd:="vipe"}"

tm -sout -vipe spv "$vipe_cmd" | cat
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
export TTY
# shopt -s nullglob # use for 'for' loops but not for 'ls', 'grep'

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
    "") { shift; }; ;;
    -oc) {
        org_link=y
        shift
    }
    ;;

    -all) {
        all=y
        shift
    }
    ;;

    *) break;
esac; done

tf_bible="/tmp/biblesearch.txt"

stdin_exists() {
    {
    ! [ -t 0 ] && \
    ! test "$(readlink /proc/$$/fd/0)" = /dev/null  && \
    ! test "$(readlink /proc/$$/fd/0)" = "$(readlink /proc/$$/fd/1)"
    # stdin may be redirected to the tty, but  will continue to say false (due to a bash bug)
    # So test to make sure 0 does not point to 1
    } &>/dev/null
}

# Can do this
# tvipify "semantic-bible-search -oc"

if stdin_exists; then
    query="$(cat)"
    exec <&2
else
    query="$@"
fi

test -n "$query" || query="$(rlwrap readln "Bible search")"

test -n "$query" || exit 1

cd $HOME/source/git/hoffa/bible-search

CMD="$(cmd python bible_search.py "$query") | chomp > $tf_bible"

oci unbuffer x -cd "$HOME/source/git/hoffa/bible-search" -sh bash -s ". .venv/bin/activate; $CMD" -c m -e '$' -c d -i &>/dev/null

test -s "$tf_bible" || exit 1

sel_to_link() {
    awk1 | while IFS=$'\n' read -r sel; do
        text="$(p "$sel" | jq -r .text | pen-str join ' ')"
        book="$(p "$sel" | jq -r .book)"
        chapter="$(p "$sel" | jq -r .chapter)"
        url="$(p "$sel" | jq -r .url)"
        link="+ [[$url][$book $chapter]] :: $text"
        printf -- "%s\n" "$link"
    done
}

if test "$org_link" = "y" && test "$all" = "y"; then
    cat "$tf_bible" | awk1 | while IFS=$'\n' read -r sel; do
        echo "$sel" | sel_to_link
    done | pavs
elif test "$org_link" = "y"; then
    sel="$(cat "$tf_bible" | mfz -nv)"

    test -n "$sel" || exit 1

    echo "$sel" | sel_to_link | pavs
else
    cat "$tf_bible" | pavs
fi