contrib / thunderbird-patch-inline / appp.shon commit Merge branch 'tz/t4038-bash-redirect-target-workaround' (3221177)
   1#!/bin/sh
   2# Copyright 2008 Lukas Sandström <luksan@gmail.com>
   3#
   4# AppendPatch - A script to be used together with ExternalEditor
   5# for Mozilla Thunderbird to properly include patches inline in e-mails.
   6
   7# ExternalEditor can be downloaded at http://globs.org/articles.php?lng=en&pg=2
   8
   9CONFFILE=~/.appprc
  10
  11SEP="-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-"
  12if [ -e "$CONFFILE" ] ; then
  13        LAST_DIR=$(grep -m 1 "^LAST_DIR=" "${CONFFILE}"|sed -e 's/^LAST_DIR=//')
  14        cd "${LAST_DIR}"
  15else
  16        cd > /dev/null
  17fi
  18
  19PATCH=$(zenity --file-selection)
  20
  21if [ "$?" != "0" ] ; then
  22        #zenity --error --text "No patchfile given."
  23        exit 1
  24fi
  25
  26cd - > /dev/null
  27
  28SUBJECT=$(sed -n -e '/^Subject: /p' "${PATCH}")
  29HEADERS=$(sed -e '/^'"${SEP}"'$/,$d' $1)
  30BODY=$(sed -e "1,/${SEP}/d" $1)
  31CMT_MSG=$(sed -e '1,/^$/d' -e '/^---$/,$d' "${PATCH}")
  32DIFF=$(sed -e '1,/^---$/d' "${PATCH}")
  33
  34CCS=$(echo -e "$CMT_MSG\n$HEADERS" | sed -n -e 's/^Cc: \(.*\)$/\1,/gp' \
  35        -e 's/^Signed-off-by: \(.*\)/\1,/gp')
  36
  37echo "$SUBJECT" > $1
  38echo "Cc: $CCS" >> $1
  39echo "$HEADERS" | sed -e '/^Subject: /d' -e '/^Cc: /d' >> $1
  40echo "$SEP" >> $1
  41
  42echo "$CMT_MSG" >> $1
  43echo "---" >> $1
  44if [ "x${BODY}x" != "xx" ] ; then
  45        echo >> $1
  46        echo "$BODY" >> $1
  47        echo >> $1
  48fi
  49echo "$DIFF" >> $1
  50
  51LAST_DIR=$(dirname "${PATCH}")
  52
  53grep -v "^LAST_DIR=" "${CONFFILE}" > "${CONFFILE}_"
  54echo "LAST_DIR=${LAST_DIR}" >> "${CONFFILE}_"
  55mv "${CONFFILE}_" "${CONFFILE}"