2021-05-12 14:32:11
Shell 終端檔案對比高亮顯示
2020-06-16 17:23:09
日常開發當中,團隊共同作業就要涉及到程式碼版本的管理,程式碼版本不斷的變化,專案合併時通常會比較同一程式碼不同版本之間具體發生了哪些變化?還有常在shell終端開發下的我們對比檔案我們又通常會用到一些對比的命令,無論是Linux的對比命令還是程式碼版本管理的對比,輸出的對比文字大都比較樸素,如果差異小還好,如果差異大簡直要崩潰,剛好看到一個小工具,也從網上查了些相關資料,覺的是一個實用的小工具,在此分享給大家。
- ColorDiff 介紹
- ColorDiff 安裝
- ColorDiff 不同場景下運用
ColorDiff 介紹
colordiff 是perl 開發一款小工具,與diff 功能一樣,但其擁有漂亮的語法和高亮差異顯示。小巧輕便又可以客製化顏色方案。colordiff 適用於 Linux 及 BSD 系統,目前已被包含到 Debian、Ubuntu、Gentoo、Arch Linux、Fedora、FreeBSD 等發行版中。—— 【官方網站】
ColorDiff 安裝
以下簡單針對幾個系統做下介紹:
Mac 系統
安裝方式
brew install colordiff
Ubuntu
apt-get install colordiff
yum install colordiff
或者手動安裝,因軟體本身很小巧,安裝也很簡單,將下載到的原始碼包解壓後,直接進行目錄中執行”make install”即可,程式和組態檔分別預設安裝在/usr/local/bin和/etc目錄下
wget http://www.colordiff.org/colordiff-1.0.16.tar.gz
tar -zxvf colordiff-1.0.16.tar.gz
cd colordiff-1.0.16
make install
ColorDiff 不同場景下的運用
- 檔案對比
對比linux 下兩檔案內容的差異:
colordiff file1 file2
- 配合diff 命令
ColorDiff用於diff命令的管道輸出:
diff -u file1 file2 | colordiff
- 配合svn diff
在 ~/.subversion/config 內修改:
[helpers]
diff-cmd = colordiff
如果需要修改顏色:sudo vim /usr/local/etc/colordiffrc
[helpers]
49 ### Set editor-cmd to the command used to invoke your text editor.
50 ### This will override the environment variables that Subversion
51 ### examines by default to find this information ($EDITOR,
52 ### et al).
53 # editor-cmd = editor (vi, emacs, notepad, etc.)
54 ### Set diff-cmd to the absolute path of your 'diff' program.
55 ### This will override the compile-time default, which is to use
56 ### Subversion's internal diff implementation.
57 # diff-cmd = diff_program (diff, gdiff, etc.)
58 ### Set diff3-cmd to the absolute path of your 'diff3' program.
59 ### This will override the compile-time default, which is to use
60 ### Subversion's internal diff3 implementation.
61 # diff3-cmd = diff3_program (diff3, gdiff3, etc.)
62 ### Set diff3-has-program-arg to 'yes' if your 'diff3' program
63 ### accepts the '--diff-program' option.
64 # diff3-has-program-arg = [yes | no]
65 ### Set merge-tool-cmd to the command used to invoke your external
66 ### merging tool of choice. Subversion will pass 4 arguments to
67 ### the specified command: base theirs mine merged
68 # merge-tool-cmd = merge_command
69 diff-cmd = colordiff
70 ### Section for configuring tunnel agents.
本文永久更新連結地址:http://www.linuxidc.com/Linux/2017-01/139809.htm
相關文章