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

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:

re-enable autoedit
[etc/mutt.git] / .mutt / mkconf
1 #!/bin/sh
2 set -eu
3
4 FILE="${1:-}"
5 TARGET="${2:-}"
6
7 if [ ! -f "$FILE" ]; then
8   echo >&2 "E: File $FILE does not exist"
9   exit 1
10 fi
11
12 if [ -z "$TARGET" ]; then
13   TARGET="$FILE"
14 fi
15
16 TMPFILE="$(mktemp -t vit.XXXXXXXX)"
17 cleanup() { rm -f "$TMPFILE"; trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15; }
18 trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
19
20 process_stanza() {
21   echo "$2"
22   local opt setting trailer
23   opt="$(sed -ne "/^set ${1}=/,/# 3\./p" $FILE)"
24   if [ -n "$opt" ]; then
25     opt="${opt%
26 *}"
27     setting="${opt%%
28 *}"
29     echo >&2 "Importing setting: $setting …"
30     echo "$setting"
31     echo "$opt" | grep '^#' || :
32   fi
33   echo
34   echo
35 }
36
37 option=
38 { zcat /usr/share/doc/mutt/manual.txt.gz | \
39   sed -e '1,/^3\. Configuration Variables$/d;1d;/^4\./,$d' -e 's, , ,g';
40   echo END; } | \
41
42 while read first rest; do
43   line="$first ${rest%% }"
44   case "$first" in
45     (3.[0-9]*|END)
46       [ -z "$option" ] || \
47         process_stanza "$option" "${stanza}"
48       stanza="# $line"
49       option="$rest"
50       ;;
51     ('')
52       stanza="${stanza:+$stanza\n}#$line"
53       ;;
54     (*)
55       stanza="${stanza:+$stanza\n}# $line"
56       ;;
57   esac
58
59 done > $TMPFILE
60
61 cat <<_eof > "$TARGET"
62 # Auto-generated using mkconf from manual.txt
63 # on $(date +'%Y-%m-%d %H:%M:%S')
64 #
65 # Invoked as: $0 $@
66 #
67
68 $(cat "$TMPFILE")
69 _eof
70 cleanup