aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Pannacciulli <jpnc@jpnc.info>2017-11-29 01:00:28 -0800
committerJames Pannacciulli <jpnc@jpnc.info>2017-11-29 01:00:28 -0800
commit0074b6f1fbc8b0a550dd7f2461b993225249a9e3 (patch)
tree816f3c3e828248ded021ad46f9b1e3b98e44d19e
parentd9141ad42b5eff24f826174bd4f4676e85ce3b20 (diff)
downloadariketa-0074b6f1fbc8b0a550dd7f2461b993225249a9e3.tar.gz
ariketa-0074b6f1fbc8b0a550dd7f2461b993225249a9e3.tar.bz2
add support for specifying custom examples file or instantiated array name
-rw-r--r--README.md6
-rw-r--r--USAGE12
-rw-r--r--ariketa.sh32
3 files changed, 39 insertions, 11 deletions
diff --git a/README.md b/README.md
index 445a68c..27c9795 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,11 @@ usage
-----
To load ariketa, source it into the bash session you wish to use for the
presentation:
- source ./ariketa.sh
+ # load examples from ariketa/config/examples.sh
+ source ariketa.sh
+
+ # load example file specified as argument
+ source ariketa.sh filename.sh
When an example is displayed, it may be edited like any command line and
executed normally by pressing enter. Use the following key bindings to
diff --git a/USAGE b/USAGE
index 7403d76..75e92a3 100644
--- a/USAGE
+++ b/USAGE
@@ -4,8 +4,12 @@ ariketa: bash example code quickloader for presentations
usage
-----
To load ariketa, source it into the bash session you wish to use for the
- presentation:
- source ./ariketa.sh
+ presentation. If no array name or filename is provided to source the
+ _examples array from, ariketa will attempt to load 'config/examples.sh'
+ from the ariketa directory:
+ source ariketa
+ source ariketa [-a|--array EXAMPLES_ARRAYNAME]
+ source ariketa [EXAMPLES_FILENAME]
When an example is displayed, it may be edited like any command line and
executed normally by pressing enter. Use the following key bindings to
@@ -30,7 +34,5 @@ configuration
-------------
To load examples into ariketa, edit the 'examples.sh' file in the
'config' directory. This file should be a sourceable bash script which
- creates an indexed array named '_examples', whose elements have values
- beginning with a tag, delineated from the example itself by a ':' character
- followed by a newline. An sample config is located in
+ creates an indexed array named '_examples'. An sample config is located in
'config/examples.sh.sample'.
diff --git a/ariketa.sh b/ariketa.sh
index 44b24ca..25df78f 100644
--- a/ariketa.sh
+++ b/ariketa.sh
@@ -10,9 +10,8 @@ _ariketa.dir () {
printf "%s" "$_ariketa_dir"
}
-
_ariketa.help () {
- >&2 printf "%s\n" "$(<USAGE)"
+ >&2 printf "%s\n" "$(<${ARIKETA_DIR:-.}${ARIKETA_DIR+/}USAGE)"
return 1
}
@@ -20,15 +19,38 @@ _sourced? () {
[[ ${FUNCNAME[$(( ${#FUNCNAME[@]} - 1 ))]} == "source" ]]
}
+ARIKETA_DIR=$(_ariketa.dir)
+
_sourced? || {
_ariketa.help
exit $?
}
-ARIKETA_DIR=$(_ariketa.dir)
+until [[ -z "$1" ]]; do
+ case "$1" in
+ -h|--help)
+ _ariketa.help
+ return $?;;
+ -a|--array)
+ # copy by indirection to set of discrete elements in named array
+ _ariketa_array_elements="${2:?Missing name parameter for '-a'}[@]"
+ _examples=( "${!_ariketa_array_elements}" )
+ shift 2;;
+ *)
+ _ariketa_examples_file="${1}"
+ [[ -r "${_ariketa_examples_file}" ]] || {
+ _ariketa.help
+ return $?
+ }
+ shift;;
+ esac
+done
-# load examples array
-source "${ARIKETA_DIR:?}/config/examples.sh"
+# load examples array from file if array not passed / copied from args
+[[ -z "${_ariketa_array_elements}" ]] && {
+ source "${_ariketa_examples_file:-${ARIKETA_DIR:?}/config/examples.sh}"
+}
+unset _ariketa_array_elements
# if examples array has no content, bail with USAGE text
(( ${#_examples[@]} )) || {