はじめに

diffコマンドだと、色がつかないのだがどうやら色をつけてくれるcolordiffコマンドがあるのでこれを使ってみる。
https://www.colordiff.org/

環境

1
2
MacOS Sonoma 14.0
Homebrew 4.1.16

colordiffのインストール

1
$ brew install colordiff
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
~/workspace/blog-hugo$brew install colordiff
==> Downloading https://formulae.brew.sh/api/formula.jws.json
################################################################################################################################ 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
################################################################################################################################ 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/colordiff/manifests/1.0.21
################################################################################################################################ 100.0%
==> Fetching colordiff
==> Downloading https://ghcr.io/v2/homebrew/core/colordiff/blobs/sha256:4f4ba10c742bc2036939397bf86b0f00a3d1992d1e72c08e7f20b77964d42b0
################################################################################################################################ 100.0%
==> Pouring colordiff--1.0.21.all.bottle.tar.gz
🍺  /usr/local/Cellar/colordiff/1.0.21: 10 files, 63.2KB
==> Running `brew cleanup colordiff`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

使ってみる

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
~/workspace/blog-hugo$colordiff --help
colordiff:
    --help                   : Displays this help
    --color=(yes|no)         : Force (or suppress) display of colours in output
    --color=patches=(yes|no) : Force (or suppress) inclusion of colour codes in patch output
    --color-term-output-only : Force (or suppress) colour to only appear in terminal output
    --difftype=DIFFTYPE      : Force difftype detection to specified format
    --(no)banner             : Show (or suppress) the colordiff banner

    DIFFTYPE is usually auto-detected, but can be set to:
          diff, diffc, diffu, diffy, debdiff or wdiff

適当なファイルを作成して、diffをしてみる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
~/workspace/blog-hugo$colordiff -u compose.yml compose.yml.2
--- compose.yml 2023-09-15 12:08:24
+++ compose.yml.2       2023-10-20 15:50:42
@@ -1,4 +1,4 @@
-# https://gohugo.io/installation/linux/#docker
+
 services:
   hugo:
     image: klakegg/hugo:0.111.3-ext-ubuntu
@@ -6,4 +6,5 @@
     volumes:
       - .:/src
     ports:
-      - "1313:1313"
\ No newline at end of file
+      - "1313:1313"
+      - "8080:8080"
diff-1

diffだと色がつかないが、colordiffだとコンソール上で色がついているのがわかる。

おわりに

サーバ上で比較することはよくあるのだが、色がないと見辛いって時がたまにある。
サーバに入れられるのであれば入れた方が良いかな程度ではあるが便利そう。