开发者

Is it possible to email the contents of vim using HTML

I like to view the current differences in the source fil开发者_如何学Goes 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-address@example.com'
  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.


I'm no Linux Guru, but this looks like it should serve your needs to pipe your output into:

Send an HTML file as email from the command line. (uses mail)

There's also a one-line mutt example here:

mutt -e "my_hdr Content-Type: text/html" 
     -s "my subject" you@xxxxxxxxxxx < message.html

this will generate a pure HTML E-Mail with no pure text alternative - for that you would have to build multi-part mail... But maybe it'll do for what you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜