From 1b09c0814cd1e5d5a57be0c45c879fe0b146d220 Mon Sep 17 00:00:00 2001 From: James Pannacciulli Date: Mon, 12 Jun 2017 11:21:21 -0700 Subject: move sample examples out of config, show USAGE if no examples --- ariketa.sh | 17 ++++++++++++++--- config/examples.sh | 22 +++++----------------- config/examples.sh.sample | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 config/examples.sh.sample diff --git a/ariketa.sh b/ariketa.sh index 658588f..38ac242 100644 --- a/ariketa.sh +++ b/ariketa.sh @@ -27,6 +27,20 @@ _sourced? || { 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 @@ -39,8 +53,5 @@ source "${ARIKETA_DIR:?}/lib/functions.sh" # set up bash macros to page through examples source "${ARIKETA_DIR:?}/lib/bindings.sh" -# load examples array -source "${ARIKETA_DIR:?}/config/examples.sh" - # unset example index/directionality markers unset _I _D diff --git a/config/examples.sh b/config/examples.sh index 41d5c0c..acb0885 100644 --- a/config/examples.sh +++ b/config/examples.sh @@ -1,20 +1,8 @@ -_examples=( - -'example tag: -echo "example command"' - -'example tag: -printf "%s\n" "this is a second example tag example"' +#!/bin/bash -'example tag: -printf "%s\n" good for measure another | sort' - -'a different tag: -echo "did you notice the tag above along with its adjacency indicators (+) ?"' - -'a different tag: -uniq \ - <(sort \ - <(printf "%s\n" "${_examples[@]//:$'\n'*/}") )' +# each array element will be an example code snippet +# code must be preceded by a tag, followed by a ':' and a newline +_examples=( + # place quoted examples here ) diff --git a/config/examples.sh.sample b/config/examples.sh.sample new file mode 100644 index 0000000..fffb4d4 --- /dev/null +++ b/config/examples.sh.sample @@ -0,0 +1,25 @@ +#!/bin/bash + +# each array element will be an example code snippet +# code must be preceded by a tag, followed by a ':' and a newline + +_examples=( + +'example tag: +echo "example command"' + +'example tag: +printf "%s\n" "this is a second example tag example"' + +'example tag: +printf "%s\n" good for measure another | sort' + +'a different tag: +echo "did you notice the tag above along with its adjacency indicators (+) ?"' + +'a different tag: +uniq \ + <(sort \ + <(printf "%s\n" "${_examples[@]//:$'\n'*/}") )' + +) -- cgit v1.2.3