blob: e614cbc5f5ca7fac984a3162e3b8f9fe5dbf840a (
plain)
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
|
# bible(1) completion -*- shell-script -*-
# These are bash completions for the bible executable
_bible()
{
local cur prev words cword split
# -s splits option=value into option in $prev and value in $cur
# -n : keeps the colon from signifying the end of a token
_init_completion -s -n : || return
case $prev in
--module | -m | --set-default-module | --remove-module)
COMPREPLY=($(compgen -W "`bible --list-modules | tail -n+2 | awk '{print $1}'`" -- "$cur"))
return
;;
--list-chapters)
# If we already have -m, use that. Else if a default is set, use that. Else, just return.
# Scan COMP_WORDS for -m or --module
mod="`grep -Po '(?<=\-m |\-\-module ).*?(?= )' <<< "${COMP_WORDS[@]}"`"
if [ -z "$mod" ]; then
# If we get here, then we need to set mod using the default module
mod="`bible --list-modules | grep '(default)' | awk '{print $1}'`"
if [ -z "$mod" ]; then
# We tried.
return
fi
fi
# Tricky because of spaces in names
books="`bible -m $mod --list-books | tail -n+2 | sed 's/^ //' | sed 's/ /\\\\ /g'`"
books="${books//\\ /___}"
COMPREPLY=()
for iter in $books; do
if [[ $iter =~ "___" ]]; then
iter="\"${iter//___/ }\""
fi
if [[ $iter =~ ^$cur ]] || [[ $iter =~ ^\"$cur ]]; then
COMPREPLY+=("$iter")
fi
done
return
;;
--install-network)
# Use cur to first grab language, then module
if [[ $cur == *:* ]]; then
# We're working on the mod, not language
lang=`cut -d: -f1 <<< $cur`
COMPREPLY=($(compgen -W "`bible --list-installable | grep -Pzo '(?s)For language '$lang':.*?(?=For language)' | tail -n+2 | sed 's/ /'$lang':/' | tr -d '\000'`" -- "$cur"))
else
# We're working on the language, not mod
compopt -o nospace
COMPREPLY=($(compgen -W "`bible --list-installable | grep 'For language' | awk '{print $3}'`" -- "$cur"))
fi
__ltrim_colon_completions "$cur"
return
;;
--install-zip)
_filedir '@(zip)'
return
;;
--list-installable)
COMPREPLY=($(compgen -W "`bible --list-installable | grep 'For language' | sed 's/For language //' | cut -d: -f1`" -- "$cur"))
return
;;
--help | --list-books | --omit-verse-numbers | --list-modules | --list-installable | -[ho])
return
;;
esac
$split && return
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W "`_parse_help "$1"`" -- "$cur"))
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
fi
} &&
complete -F _bible bible
|