# Mutt inline patch handling

Developers like to send diffs inline in emails. They do this, because
it's fast and easy to read through them, comment on them and also to
apply them. Many version control systems take over the email text into
the patch description as well.

Up to now, my workflow was manual. I had to save the email somewhere,
tthen open a terminal, cd to the direcory the patch shall be applied in
and call the patch utility with the path to the saved email as argument.

No more.

This mutt macro takes the current visible email and copies it to a
ttemporary file (/tmp/mutt-patch.diff). Then it executes the portpatch.sh
shell script. All with one push on ctrl+s while looking at the email.

The macro must be written in one line and ^S can be entered with the
keyboard sequence ctrl+v ctrl+s:

```
macro pager ^S "<shell-escape>rm -f /tmp/mutt-patch.diff<enter><copy-message>/tmp/mutt-patch.diff<enter><enter-command>echo 'Saved as /tmp/mutt-patch.diff'<enter><shell-escape>~/.mutt/scripts/portpatch.sh /tmp/mutt-patch.diff<enter>"
```

The portpatch.sh script:

```
#!/bin/sh

printf '\n-------------------------------------------------------\n'
cat "$1" | egrep ^Index\|^RCS\|--git
printf '-------------------------------------------------------\n\n'

printf "Path for patch [/usr/ports]? "
read _path

[ -z "$_path" ] && _path=/usr/ports

doas patch -p0 -d $_path < "$1"
cd $_path && ksh
```

The script shows some relvant bits from the email patch that are handy 
tto determine on which path the patch shall be applied.

Next it alles the user to enter a different path. I most use /usr/ports, 
so this is the default. Then the patch is applied and a ksh shell is 
opened for further work.

Quitting the shell brings me back to mutt to work on the next email.

This is quite friggin handy.
