aboutsummaryrefslogtreecommitdiffstats
path: root/ariketa.sh
blob: 38ac242838cde704b93a1e790f2f0a2cba9bd199 (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
#!/bin/bash

_ariketa.dir () {
    local _ariketa_filename _ariketa_dir
    _ariketa_filename="${BASH_SOURCE[$(( ${#BASH_SOURCE[@]} - 1 ))]}"
    [[ "$_ariketa_filename" == */* ]] && _ariketa_dir="${_ariketa_filename%/*}"

    # get an absolute path to ariketa in case we need it
    _ariketa_dir=$(cd "${_ariketa_dir:-$PWD}" && printf "%s" "$PWD")
    printf "%s" "$_ariketa_dir"
}


_ariketa.help () {
    >&2 printf "%s\n" "$(<USAGE)"
    return 1
}

_sourced? () {
    [[ ${FUNCNAME[$(( ${#FUNCNAME[@]} - 1 ))]} == "source" ]]
}

_sourced? || {
    _ariketa.help
    exit $?
}

ARIKETA_DIR=$(_ariketa.dir)

# load examples array
source "${ARIKETA_DIR:?}/config/examples.sh"

# if examples array has no content, bail with USAGE text
(( ${#_examples[@]} )) || {
    >&2 printf "**  %s\n" \
        "" ""\
        "$(declare -p _examples)"\
        "_examples array needs content -- see 'configuration' below"\
        "" ""
    _ariketa.help
    return $?
}

# preserve multiline commands as such in history
shopt -s lithist

# load presentation prompt
source "${ARIKETA_DIR:?}/lib/prompt.sh"

# load misc functions
source "${ARIKETA_DIR:?}/lib/functions.sh"

# set up bash macros to page through examples
source "${ARIKETA_DIR:?}/lib/bindings.sh"

# unset example index/directionality markers
unset _I _D