当我有一个差异时,我如何给它上色,使它看起来更好?
我想它的命令行,所以请没有GUI解决方案。
当我有一个差异时,我如何给它上色,使它看起来更好?
我想它的命令行,所以请没有GUI解决方案。
当前回答
对我来说,我找到了一些解决方案:这是一个有效的解决方案
@echo off
Title a game for YouTube
explorer "https://thepythoncoding.blogspot.com/2020/11/how-to-echo-with-different-colors-in.html"
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo say the name of the colors, don't read
call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"
goto :Beginoffile
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
:Beginoffile
其他回答
你可以改变Subversion配置使用colordiff:
~ / .subversion / config.diff
### Set diff-cmd to the absolute path of your 'diff' program.
### This will override the compile-time default, which is to use
### Subversion's internal diff implementation.
-# diff-cmd = diff_program (diff, gdiff, etc.)
+diff-cmd = colordiff
通过https://gist.github.com/westonruter/846524
我最喜欢的选择是vdiff <file1> <file2>函数(我忘记从哪里得到它)。
它将在Vim中并排打开两个窗口,以清楚地看到两个文件之间的差异。
vdiff () {
if [ "${#}" -ne 2 ] ; then
echo "vdiff requires two arguments"
echo " comparing dirs: vdiff dir_a dir_b"
echo " comparing files: vdiff file_a file_b"
return 1
fi
local left="${1}"
local right="${2}"
if [ -d "${left}" ] && [ -d "${right}" ]; then
vim +"DirDiff ${left} ${right}"
else
vim -d "${left}" "${right}"
fi
}
将这个脚本放在您的(.alias)或(.zshrc)中,然后使用 Vdiff <file1> <file2>. Vdiff <file1>。
例子
结果如下:
我使用grc(通用着色器),它允许您对包括diff在内的许多命令的输出进行着色。
它是一个Python脚本,可以封装在任何命令中。因此,不是调用diff file1 file2,而是调用grc diff file1 file2来查看着色的输出。我有别名diff到grc diff使它更容易。
实际上,似乎还有另一个选择(我最近才注意到,当遇到上面描述的问题时):
git diff --no-index <file1> <file2>
# output to console instead of opening a pager
git --no-pager diff --no-index <file1> <file2>
如果您身边有Git(您可能已经在使用它了),那么您将能够使用它进行比较,即使文件本身不受版本控制。如果默认情况下没有启用,那么在这里启用颜色支持似乎比前面提到的一些变通方法要容易得多。
到目前为止还没有人提到delta。它支持带有语法高亮的语法彩色差异视图。