Skip to content

Instantly share code, notes, and snippets.

@gggeek
Created February 11, 2023 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gggeek/a836fa51229d31985fe67515d6c3d7e4 to your computer and use it in GitHub Desktop.
Save gggeek/a836fa51229d31985fe67515d6c3d7e4 to your computer and use it in GitHub Desktop.
taskfile ("make-like" but in bash) with better docs generation than the original
# this comment will be in the help text for a_task
function a_task() {
...
}
# prints this help text
function help() {
# @todo allow a tag such as `# @internal` to denote functions as not available for external execution
declare -A DESCRIPTIONS
local CMD MAX LEN
echo "$0 <task> <args>"
echo "Tasks:"
MAX=-1
for CMD in $(compgen -A function); do
LEN=${#CMD}
((LEN > MAX)) && MAX=$LEN
DESCRIPTIONS[$CMD]=$(grep "function $CMD(" -B 1 "${BASH_SOURCE[0]}" | grep '^#' | grep -v '@todo' | sed 's/^# *//')
done
MAX=$((MAX + 4))
for CMD in $(compgen -A function); do
if [ -z "${DESCRIPTIONS[$CMD]}" ]; then
echo " ${CMD}"
else
printf "%-${MAX}s %s\n" " ${CMD}" "${DESCRIPTIONS[$CMD]}"
#echo " ${CMD}: ${DESCRIPTIONS[$CMD]}"
fi
done
}
if [ $# -eq 0 ]; then
help
else
cd "$(dirname -- "$(realpath "${BASH_SOURCE[0]}")")"
TIMEFORMAT="Task completed in %3lR"
time ${@}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment