LoginSignup
1
0
お題は不問!Qiita Engineer Festa 2024で記事投稿!
Qiita Engineer Festa20242024年7月17日まで開催中!

colordiffを使って見づらいdiffコマンドからおさらばしよう!

Last updated at Posted at 2024-06-19

背景

diffコマンド、見づらい…。

なんかいいのないかな?

colordiffを使おう

インストール方法

$ brew install colordiff
$ apt-get install colordiff

ファイルの準備

text01.txt
$ cat text01.txt
aaa
bbb
ccc
ddd
eee
fff
text02.txt
$ cat text02.txt
aa11a
bbb
ccc222
ddd
eee333
fff

出力例(-uなし)

$ diff text01.txt text02.txt

スクリーンショット 2024-06-19 14.37.47.png

$ colordiff text01.txt text02.txt

スクリーンショット 2024-06-19 14.37.55.png

出力例(-uあり)

$ diff -u text01.txt text02.txt

スクリーンショット 2024-06-19 14.38.47.png

$ colordiff -u text01.txt text02.txt

スクリーンショット 2024-06-19 14.38.54.png

おまけ (aliasの対応)

alias diff='colordiff -u' と設定すると colordiff がインストールされていない環境ではダメなので以下のように設定しました。
-u オプションをつけると git diff の出力に近くなります。

.zshrcファイルをopen

$ vi ~/.zshrc

以下を記載

.bashrc
if [[ -x `which colordiff` ]]; then
  alias diff='colordiff -u'
else
  alias diff='diff -u'
fi

.zshrcファイルをsave

$ source ~/.zshrc

参考記事

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0