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