I like to view the current differences in the source files I'm working on with a command like:
vim <(svn diff -dub)
What I'd really like to be able to do is to email that colorized diff. I know vim can export HTML with the :TOhtml, but how do I pipeline this output into an html email? Ideally. i'd like to be able to send an html diff with a single shell script command.
The following one-liner produces an HTML file named email.html
:
diff file1 file2 | vim - +TOhtml '+w email.html' '+qall!'
You can now use Pekka’s code to send the email.
However, I believe in using the right tool for the right job – and VIM may not be the right tool here. Other highlighters exist and their use is more appropriate here.
For example, Pygments can be harnessed to produce the same result, much more efficiently and hassle-free:
diff -u report.log .report.log | pygmentize -l diff -f html > email.html
Notice that this produces only the actual text body, not the style sheet, nor the surrounding HTML scaffold. This must be added separately but that’s not difficult either. Here’s a complete bash script to produce a valid minimal HTML file:
echo '<!DOCTYPE html><html><head><title>No title</title><style>' > email.html
pygmentize -S default -f html >> email.html
echo '</style></head><body>' >> email.html
diff -u report.log .report.log | pygmentize -l diff -f html >> email.html
echo '</body></html>' >> email.html
EDIT In case that Pekka’s code didn’t work – as for me – because you don’t have the required versions of mail
and mutt
installed then you can use sendmail
as follows to send the HTML email:
( echo 'To: [email protected]'
echo 'Content-Type: text/html'
echo 'Subject: test'
echo ''
cat email.html ) | sendmail -t
It’s important to leave an empty line between the header and the body of the email. Also, notice that it’s of course unnecessary to create the temporary file email.html
. Just paste the rest of the commands into the right place above and delete the redirects to file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With