update to latest version of composure.sh
authorErich Smith <heartquest@gmail.com>
Fri, 11 May 2012 18:10:39 +0000 (14:10 -0400)
committerErich Smith <heartquest@gmail.com>
Mon, 14 May 2012 02:13:03 +0000 (22:13 -0400)
this fixes a bug in draft() and improves performance in metafor()
and glossary()

lib/composure.sh

index d21281d..8ca66d6 100644 (file)
@@ -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 ()