git-vendor-name: composure
git-vendor-dir: vendor/github.com/erichs/composure
git-vendor-repository: https://github.com/erichs/composure
git-vendor-ref: 55fdb9fa3cd0f181208a46d90da4d87d5b7e4351
This commit is contained in:
cornfeedhobo
2021-02-05 00:15:02 -06:00
4 changed files with 46 additions and 14 deletions

View File

@@ -58,14 +58,14 @@ _determine_printf_cmd() {
if [ -z "$_printf_cmd" ]; then
_printf_cmd=printf
# prefer GNU gprintf if available
[ -x "$(which gprintf)" ] && _printf_cmd=gprintf
[ -x "$(which gprintf 2>/dev/null)" ] && _printf_cmd=gprintf
export _printf_cmd
fi
}
_longest_function_name_length ()
{
_typeset_functions | awk 'BEGIN{ maxlength=0 }
echo "$1" | awk 'BEGIN{ maxlength=0 }
{
for(i=1;i<=NF;i++)
if (length($i)>maxlength)
@@ -175,22 +175,33 @@ _transcribe ()
_typeset_functions ()
{
typeset f
for f in "$(_get_composure_dir)"/*.inc; do
# Without nullglob, we'll get back the glob
[[ -f "$f" ]] || continue
# unfortunately, there does not seem to be a easy, portable way to list just the
# names of the defined shell functions...
f="${f##*/}"
f="${f%.inc}"
echo "$f"
done | cat - <(echo "cite\ndraft\nglossary\nmetafor\nreference\nrevise\nwrite") | sort | uniq
case "$(_shell)" in
sh|bash)
typeset -F | awk '{print $3}'
;;
*)
# trim everything following '()' in ksh/zsh
typeset +f | sed 's/().*$//'
;;
esac
}
_typeset_functions_about ()
{
typeset f
for f in $(_typeset_functions); do
typeset -f -- "$f" | grep -qE "^about[[:space:]]|[[:space:]]about[[:space:]]" && echo -- "$f"
done
}
_shell () {
# here's a hack I modified from a StackOverflow post:
# get the ps listing for the current process ($$), and print the last column (CMD)
# stripping any leading hyphens shells sometimes throw in there
typeset this=$(ps -p $$ | tail -1 | awk '{print $4}' | sed 's/^-*//')
typeset this=$(ps -o comm -p $$ | tail -1 | awk '{print $NF}' | sed 's/^-*//')
echo "${this##*/}" # e.g. /bin/bash => bash
}
@@ -329,9 +340,10 @@ glossary ()
group 'composure'
typeset targetgroup=${1:-}
typeset maxwidth=$(_longest_function_name_length | awk '{print $1 + 5}')
typeset functionlist="$(_typeset_functions_about)"
typeset maxwidth=$(_longest_function_name_length "$functionlist" | awk '{print $1 + 5}')
for func in $(_typeset_functions); do
for func in $(echo $functionlist); do
if [ "X${targetgroup}X" != "XX" ]; then
typeset group="$(typeset -f -- $func | metafor group)"
@@ -528,7 +540,7 @@ _bootstrap_composure
: <<EOF
License: The MIT License
Copyright © 2012, 2013 Erich Smith
Copyright © 2012, 2016 Erich Smith
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software