whatnow2 save metainformation in the draft itself
[mmh] / uip / whatnow2.sh
index 91ff5a5..f9cf255 100755 (executable)
@@ -45,7 +45,7 @@ get_editor()
 {
        if [ -f "$mhmetafile" ]
        then
-               lasteditor=`anno -list -component 'last-editor' $mhmetafile`
+               lasteditor=`anno -list -component 'mmh-last-editor' "$mhmetafile"`
                if [ -n "$lasteditor" ]
                then
                        editor=`echo $lasteditor | cut -d ' ' -f 1`
@@ -63,6 +63,14 @@ get_editor()
        mheditor=`mhparam 'Editor'`
 }
 
+save_config()
+{
+       component="$1"
+       newtext="$2"
+       anno -delete -number all -component "$component" "$mhmetafile"
+       anno -nodate -component "$component" -text "$newtext" "$mhmetafile"
+}
+
 get_showproc()
 {
        mhshowproc=`mhparam 'listproc'`
@@ -78,50 +86,31 @@ get_realpath()
        cd "$OLDPWD"
 }
 
-set_lasteditor()
-{
-       anno -delete -number all -component 'last-editor' $mhmetafile
-       anno -nodate -component 'last-editor' -text "$1" $mhmetafile
-}
-
 create()
 {
        if [ -z "$mhdraft" ]
        then
                usage 1
        fi
-       mhmetafile=$mhdraft.meta
-       touch $mhmetafile
+       mhext=`mhparam Metafile-Extension`
+       mhmetafile="$mhdraft""$mhext"
+       touch "$mhmetafile"
        if [ -z "$mheditor" ]
        then
                get_editor
        fi
        if [ "$mhuse" -eq 1 ]
        then
+               exec $mheditor $mhdraft
                return
        fi
-       if [ -n "$mhaltmsg" ]
-       then
-               anno -nodate -component 'mhaltmsg' -text "$mhaltmsg" $mhmetafile
-       fi
-       if [ -n "$mhdist" ]
-       then
-               anno -nodate -component 'mhdist' -text "$mhdist" $mhmetafile
-       fi
-       if [ -n "$mhfolder" ]
-       then
-               anno -nodate -component 'mhfolder' -text "$mhfolder" $mhmetafile
-       fi
-       if [ -n "$mhmessages" ]
-       then
-               anno -nodate -component 'mhmessages' -text "$mhmessages" $mhmetafile
-       fi
-       if [ -n "$mhannotate" ]
-       then
-               anno -nodate -component 'mhannotate' -text "$mhannotate" $mhmetafile
-       fi
-       set_lasteditor "$mheditor"
-       exec $mheditor $mhdraft
+       save_config mmh-mhaltmsg "$mhaltmsg"
+       save_config mmh-mhdist "$mhdist"
+       save_config mmh-mhfolder "$mhfolder"
+       save_config mmh-mhmessages "$mhmessages"
+       save_config mmh-mhannotate "$mhannotate"
+       save_config mmh-last-editor "$mheditor"
+       exec $mheditor "$mhdraft"
 }
 
 edit()
@@ -133,8 +122,8 @@ edit()
                mheditor="$@"
        fi
 
-       set_lasteditor "$mheditor"
-       exec $mheditor $mhdraft
+       save_config mmh-last-editor "$mheditor"
+       exec $mheditor "$mhdraft"
 }
 
 list()
@@ -145,13 +134,23 @@ list()
 
 sendfunktion()
 {
-       export mhaltmsg=`anno -list -component 'mhaltmsg' "$mhmetafile"`
-       export mhdist=`anno -list -component 'mhdist' "$mhmetafile"`
-       export mhfolder=`anno -list -component 'mhfolder' "$mhmetafile"`
-       export mhmessages=`anno -list -component 'mhmessages' "$mhmetafile"`
-       export mhannotate=`anno -list -component 'mhannotate' "$mhmetafile"`
+       export mhaltmsg=`anno -list -component 'mmh-mhaltmsg' "$mhmetafile"`
+       export mhdist=`anno -list -component 'mmh-mhdist' "$mhmetafile"`
+       export mhfolder=`anno -list -component 'mmh-mhfolder' "$mhmetafile"`
+       export mhmessages=`anno -list -component 'mmh-mhmessages' "$mhmetafile"`
+       export mhannotate=`anno -list -component 'mmh-mhannotate' "$mhmetafile"`
+       tmp=`mktemp`
+       cp "$mhdraft" "$tmp"
+       mhl -form mhl.whatnow2 "$tmp" > "$mhdraft"
+       mhle="$?"
+       if [ "$mhle" -ne 0 ]
+       then
+               mv "$tmp" "$mhdraft"
+               exit "$mhle"
+       fi
        send "$@" "$mhdraft" || exit $?
        rm -f "$mhmetafile"
+       rm -f "$tmp"
        exit 0
 }
 
@@ -206,7 +205,7 @@ detach()
 
 display()
 {
-       mhaltmsg=`anno -list -component 'mhaltmsg' "$mhmetafile"`
+       mhaltmsg=`anno -list -component 'mmh-mhaltmsg' "$mhmetafile"`
        get_showproc
        if [ -z "$mhaltmsg" ]
        then
@@ -243,7 +242,8 @@ then
                ;;
        esac
 fi
-mhmetafile="$mhdraft".meta
+mhext=`mhparam Metafile-Extension`
+mhmetafile="$mhdraft""$mhext"
 touch "$mhmetafile"