Sfoglia il codice sorgente

feat: difftastic as default git diff + watcher-agnostic rerun helper

- bin/git-difft: wrapper used as git's diff.external — renders with difftastic
  when installed, falls back to a plain unified diff otherwise (always exits 0
  so `git diff` never reports "external diff died").
- .gitconfig_difftastic: set diff.external + pager.diff=less so `git diff` shows
  difftastic side-by-side; log/show/add -p keep the internal diff + delta pager.
- applications.sh: put ~/dotfiles/bin on PATH (also exposes uv-upgrade etc).
- aliases.sh: `rerun <cmd>` uses whichever file watcher is installed
  (watchexec preferred, else entr) so configs stay portable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Tom McKenzie 1 mese fa
parent
commit
3c29993ed4
4 ha cambiato i file con 37 aggiunte e 0 eliminazioni
  1. 8 0
      .gitconfig_difftastic
  2. 12 0
      .rc.d/aliases.sh
  3. 3 0
      .rc.d/applications.sh
  4. 14 0
      bin/git-difft

+ 8 - 0
.gitconfig_difftastic

@@ -1,5 +1,9 @@
 [diff]
     tool = difftastic
+    # make difftastic the default for `git diff`, via a wrapper that falls back
+    # to plain diff if difft isn't installed (see ~/dotfiles/bin/git-difft).
+    # git log/show/add -p keep using the internal diff + delta pager.
+    external = git-difft
 
 [difftool]
     prompt = false
@@ -9,6 +13,10 @@
 
 [pager]
     difftool = true
+    # page `git diff` (now difftastic output) with less, NOT delta — delta would
+    # garble difftastic's already-formatted output. core.pager=delta still applies
+    # to log/show/blame.
+    diff = less -R
 
 [alias]
     dft = difftool

+ 12 - 0
.rc.d/aliases.sh

@@ -126,3 +126,15 @@ ts() {
     tmux attach \; choose-tree -Zs -F "$fmt" 2>/dev/null || echo "no tmux sessions"
   fi
 }
+
+# rerun <cmd...> — re-run a command whenever files under the cwd change, using
+# whichever file watcher is installed (watchexec preferred, else entr). Lets the
+# same alias work across machines that have one or the other.
+if command -v watchexec >/dev/null 2>&1; then
+  rerun() { watchexec --restart -- "$@"; }
+elif command -v entr >/dev/null 2>&1; then
+  # entr takes the file list on stdin; feed it everything under cwd minus .git
+  rerun() { find . -type f -not -path '*/.git/*' | entr -r -- "$@"; }
+else
+  rerun() { echo "rerun: install watchexec or entr" >&2; return 127; }
+fi

+ 3 - 0
.rc.d/applications.sh

@@ -14,5 +14,8 @@ if [ -d "$HOME/.rbenv" ]; then
   eval "$(rbenv init -)"
 fi
 
+# dotfiles bin/ helpers (aws-profile, uv-upgrade, git-difft, ...)
+[ -d "$HOME/dotfiles/bin" ] && export PATH="$PATH:$HOME/dotfiles/bin"
+
 # shhh
 export HOMEBREW_NO_ENV_HINTS=1

+ 14 - 0
bin/git-difft

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+# git diff.external wrapper: render diffs with difftastic when it's installed,
+# else fall back to a plain unified diff so `git diff` never hard-fails on a
+# machine without difft.
+#
+# git calls an external differ with 7 args:
+#   path  old-file  old-hex  old-mode  new-file  new-hex  new-mode
+if command -v difft >/dev/null 2>&1; then
+  exec difft "$@"
+fi
+# Fallback: plain unified diff. `diff` exits 1 when files differ, but git treats a
+# non-zero exit from an external differ as failure ("external diff died"), so we
+# swallow it and always exit 0.
+diff -u -L "a/$1" -L "b/$1" -- "$2" "$5" || true