LoginSignup
40
39

More than 5 years have passed since last update.

git 2.9 の Beautiful diffs を活かす設定

Last updated at Posted at 2016-06-15

昨日リリースされた git 2.9 の新機能のうち Beautiful diffs 関連の設定を自分の gitconfig に足してみたのでそのメモ。

設定ファイル

gitconfig

diff-highlight が使えない場合は cat にフォールバックするとか、コピペするだけで使えるよう環境に配慮もしてみた。軽く動作確認したところ問題なく動いてる。

~/.gitconfig
diff --git a/config/git/config b/config/git/config
index 3b78506..971396f 100644
--- a/config/git/config
+++ b/config/git/config
@@ -15,6 +15,14 @@
   open = browse
 [core]
   autocrlf = false
+[pager]
+  log  = (diff-highlight 2>/dev/null || cat) | ${PAGER:-less}
+  show = (diff-highlight 2>/dev/null || cat) | ${PAGER:-less}
+  diff = (diff-highlight 2>/dev/null || cat) | ${PAGER:-less}
+[interactive]
+  diffFilter = (diff-highlight 2>/dev/null || cat)
+[diff]
+  compactionHeuristic = true
 [merge]
   ff = false
 [pull]

bashrc

あとは diff-highlight への PATH 通しだが、無闇に PATH を追加するのは好きじゃないので PATH が通ってるはずの場所に実体への symlink を作ることにする。
また、それを各環境毎に手でファイルコピーしたりとかは絶対忘れるので、この準備作業自体も自動化しておく。

~/.bashrc
# diff-highlight がローカルにあれば使えるようにする
if ! PATH=~/bin:$PATH type -P diff-highlight >/dev/null 2>&1; then
  (
  for prefix in /usr/local /usr "$DOTFILES_LOCAL"; do
    for path in share/git-core/contrib/{,diff-highlight/}diff-highlight; do
      if [[ -f $prefix/$path && -x $prefix/$path ]]; then
        ln -sfn "$prefix/$path" "$DOTFILES_LOCAL/bin/diff-highlight"
        exit
      fi
    done
  done
  )
fi

ローカルに見つからなかったら最終手段で 最新の diff-highlight を直接DLする処理を足そうかと思ったけど、よく考えたら diff-highlightが見つからない環境 == git-2.9未満 だろうからあっても意味ないと思ってそれはしてない。

40
39
1

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
40
39