]> git.madduck.net Git - etc/mutt.git/blob - .mutt/edit-header

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

07817d25924c40201cd7f74808c053bad75da7d6
[etc/mutt.git] / .mutt / edit-header
1 #!/bin/sh
2 #
3 # edit-header - helper script to append/replace/remove headers with mutt
4 #
5 # Based on an idea by David Champion <dgc at uchicago.edu>
6 #
7 # Copyright © 2008 martin f. krafft <madduck@madduck.net>
8 # Released under the terms of the Artistic Licence 2.0
9 #
10 set -eu
11
12 if [ ! -x "$(command -v formail)" ]; then
13   echo E: formail not installed. >&2
14   exit 1
15 fi
16
17 header="${1:-}"
18 if [ -z "$header" ]; then
19   echo "E: no header specified" >&2
20   exit 1
21 fi
22
23 get_header_contents()
24 {
25   local contents
26   printf "Enter ${1:-header} contents: " >/dev/tty
27   read contents </dev/tty
28   echo "$contents"
29 }
30
31 script="${0%/*}/${2:-}"
32 if [ -f "$script" ] && [ -x "$script" ]; then
33   contents_source="$script"
34   shift
35 else
36   contents_source=get_header_contents
37 fi
38
39 editor=
40 case "$0" in
41   *append-header|*supersede-header|*replace-header)
42     contents="${2:-}"
43     [ -n "$contents" ] || contents="$(eval $contents_source $header)"
44     case "$0" in
45       *append-header) flag=-A;;
46       *supersede-header) flag=-i;;
47       *replace-header) flag=-I;;
48     esac
49     editor="${0%/*}/filter-proxy formail $flag \'$header: $contents\'"
50     ;;
51
52   *remove-header)
53     editor="${0%/*}/filter-proxy formail -I \'$header:\'"
54     ;;
55
56   *)
57     echo "E: unknown invocation: ${0##*/}" >&2
58     exit 1
59     ;;
60
61 esac
62
63 echo "set my_editor=\"\$editor\""
64 echo "set my_filter=\"$editor\""
65 echo -n "push '"
66 echo -n "<enter-command>set editor=\"\$my_filter\"<enter>"
67 echo -n "<edit>"
68 echo -n "<enter-command>set editor=\"\$my_editor\"<enter>"
69 echo -n "<enter-command>unset my_filter<enter>"
70 echo -n "<enter-command>unset my_editor<enter>"
71 echo "'"