彩色 Git 与 HTML 的差异 [英] Coloured Git diff to HTML

查看:16
本文介绍了彩色 Git 与 HTML 的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 git diff --color-words 来清楚地看到文件中已更改的单词:

但是,我想与没有 git 或彩色终端的人分享该差异.那么有谁知道可以将彩色转义终端输出转换为 HTML 的工具或技巧?

解决方案

wget "http://www.pixelbeat.org/scripts/ansi2html.sh" -O/tmp/ansi2html.shchmod +x/tmp/ansi2html.shgit diff --color-words --no-index orig.txtedited.txt |/tmp/ansi2html.sh >2beshared.html

我真正需要的是一个 ANSI 到 HTML 的转换器.我在 http://www.pixelbeat.org/ 上找到了一个非常不错的.

注意:除非您包含 --color--color-words,否则您可能看不到任何颜色,这可能是因为管道导致 git diff 排除颜色.

注意 2:您可能需要安装 gnu sed 和 awk,特别是如果您使用的是 Mac.使用 brew install gnu-sed gawk 执行此操作.您可能还需要手动将它们添加到您的路径中,例如使用 ln -s/usr/local/Cellar/gnu-sed/4.2.2/bin/gsed/usr/local/bin/.

I enjoy using git diff --color-words to clearly see the words that have changed in a file:

However I want to share that diff with someone without git or a colour terminal for that matter. So does anyone know of a tool or trick that can convert colour escaped terminal output into HTML?

解决方案

wget "http://www.pixelbeat.org/scripts/ansi2html.sh" -O /tmp/ansi2html.sh
chmod +x /tmp/ansi2html.sh
git diff --color-words --no-index orig.txt edited.txt | 
/tmp/ansi2html.sh > 2beshared.html

What I really needed was an ANSI to HTML converter. And I found a very decent one on http://www.pixelbeat.org/.

NOTE: You might not see any coloration unless you include --color or --color-words, probably because piping causes git diff to exclude colors.

NOTE 2: You may need to install gnu sed and awk, especially if you're on a Mac. Do so with brew install gnu-sed gawk. You may need to add them to your path manually, too, e.g. with ln -s /usr/local/Cellar/gnu-sed/4.2.2/bin/gsed /usr/local/bin/.

这篇关于彩色 Git 与 HTML 的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆