From patchwork Sat Oct 29 17:27:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2] contrib/nmbug: new script for sharing tags with prefix notmuch:: Date: Sat, 29 Oct 2011 16:27:33 -0000 From: David Bremner X-Patchwork-Id: 1436 Message-Id: <1319909253-14045-1-git-send-email-david@tethera.net> To: notmuch@notmuchmail.org Cc: David Bremner From: David Bremner In this initial version, we take care of import and export of the appropriate tags in line oriented format amenable to easy merging. We also provide (not very robust/clever) commands commit/push/pull to deal with a git repo that as already been set up. --- fixed silly debugging output. add some convenience commands. contrib/nmbug | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 0 deletions(-) create mode 100755 contrib/nmbug diff --git a/contrib/nmbug b/contrib/nmbug new file mode 100755 index 0000000..a449d60 --- /dev/null +++ b/contrib/nmbug @@ -0,0 +1,77 @@ +#!/bin/bash +# Copyright (c) 2011 David Bremner +# License: same as notmuch + +NMHOME=${HOME}/.nmbug + +NMTAGS=($(notmuch search --output=tags "*"|grep "^notmuch::")) + +function dump() { + notmuch dump -- $(printf " tag:%s" ${NMTAGS[*]}) |\ + while read -r msgid rest + do + outfile=$NMHOME/tags/$(echo $msgid | sha1sum - | cut -f1 -d' ') + printf "msg-id: %s\n" $msgid > $outfile + tmp=${rest#\(} + read -r -a tags <<<${tmp%\)}; + for tag in "${tags[@]}"; do + case $tag in + notmuch::*) + echo "tag: $tag" >> $outfile + ;; + *) + # nothing + esac + done + done + +} + +function cat_file() { + tags="" + id="" + cat $1 |\ + while read -r what data + do + case $what in + msg-id:) + printf "%s (" $data + ;; + tag:) + printf "%s " $data + ;; + *) + echo "Syntax error $what" + exit 1 + esac + done + echo ")" +} + +function restore() { + find $NMHOME/tags -type f |\ + while read -r filename + do + cat_file $filename + done | notmuch restore --match=notmuch:: +} +case $1 in + dump) + dump + ;; + restore) + restore + ;; + commit) + (cd $NMHOME && git add tags && git commit) + ;; + push) + (cd $NMHOME && git push) + ;; + pull) + (cd $NMHOME && git pull) + ;; + *) + echo unknown command $1; +esac +