From a385e0f32e56438656c782b7931bbca7f91193d7 Mon Sep 17 00:00:00 2001 From: Erich Smith Date: Fri, 11 May 2012 14:10:39 -0400 Subject: [PATCH] update to latest version of composure.sh this fixes a bug in draft() and improves performance in metafor() and glossary() --- lib/composure.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/composure.sh b/lib/composure.sh index d21281d..8ca66d6 100644 --- a/lib/composure.sh +++ b/lib/composure.sh @@ -228,8 +228,21 @@ draft () return fi + # aliases bind tighter than function names, disallow them + if [ -n "$(type -a $func | grep 'is.*alias')" ]; then + printf '%s\n' "sorry, $(type -a $func). please choose another name." + return + fi + if [ -z "$num" ]; then - cmd=$(fc -ln -1 | head -1 | sed 's/^[[:blank:]]*//') + # parse last command from fc output + # some versions of 'fix command, fc' need corrective lenses... + typeset myopic=$(fc -ln -1 | grep draft) + typeset lines=1 + if [ -n "$myopic" ]; then + lines=2 + fi + cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//') else # parse command from history line number cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//') @@ -252,13 +265,13 @@ glossary () typeset targetgroup=${1:-} for func in $(typeset_functions); do - typeset about="$(typeset -f $func | metafor about)" if [ -n "$targetgroup" ]; then typeset group="$(typeset -f $func | metafor group)" if [ "$group" != "$targetgroup" ]; then continue # skip non-matching groups, if specified fi fi + typeset about="$(typeset -f $func | metafor about)" letterpress "$about" $func done } @@ -281,8 +294,8 @@ metafor () # this sed-fu is the retrieval half of the 'metadata' system: # 'grep' for the metadata keyword, and then parse/filter the matching line - # strip ending ; # ignore thru keyword # print remainder # strip start/end quotes - sed -n "s/;$//;s/^[ ]*$keyword \([^([].*\)*$/\1/p" | sed "s/^['\"]*//;s/['\"]*$//" + # grep keyword # strip trailing '|"|; # ignore thru keyword and leading '|" + sed -n "/$keyword / s/['\";]*$//;s/^[ ]*$keyword ['\"]*\([^([].*\)*$/\1/p" } reference () -- 2.17.1