]> git.madduck.net Git - etc/mutt.git/blob - .config/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:

add siby alternate
[etc/mutt.git] / .config / 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   if [ -z "${__RLWRAPPED:-}" ] && [ -x $(command -v rlwrap) ]; then
34     __RLWRAPPED=true exec rlwrap "$0" "$@"
35   fi
36
37   contents_source="$script"
38   shift
39 else
40   contents_source=get_header_contents
41 fi
42
43 editor=
44 case "$0" in
45   *append-header|*supersede-header|*replace-header)
46     contents="${2:-}"
47     [ -n "$contents" ] || contents="$(eval $contents_source $header)"
48     case "$0" in
49       *append-header) flag=-A;;
50       *supersede-header) flag=-i;;
51       *replace-header) flag=-I;;
52     esac
53     editor="${0%/*}/filter-proxy formail $flag \'$header: $contents\'"
54     ;;
55
56   *remove-header)
57     editor="${0%/*}/filter-proxy formail -I \'$header:\'"
58     ;;
59
60   *)
61     echo "E: unknown invocation: ${0##*/}" >&2
62     exit 1
63     ;;
64
65 esac
66
67 echo "set my_editor=\"\$editor\""
68 echo "set my_filter=\"$editor\""
69 echo -n "push '"
70 echo -n "<enter-command>set editor=\"\$my_filter\"<enter>"
71 echo -n "<edit>"
72 echo -n "<enter-command>set editor=\"\$my_editor\"<enter>"
73 echo -n "<enter-command>unset my_filter<enter>"
74 echo -n "<enter-command>unset my_editor<enter>"
75 echo "'"