Last active
November 14, 2022 09:19
-
-
Save borkdude/febec7a576a7ef793fe100df4252218d to your computer and use it in GitHub Desktop.
Difftastic wrapper with support for viewing transit.json as edn files in git diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
;; To use, call `git config diff.external "/path/to/difft.bb"` | |
;; Original by https://twitter.com/OneMore2ThePile/status/1589355270995836928 | |
;; See https://twitter.com/borkdude/status/1589359697710133248/photo/1 for a demo | |
(ns difft | |
(:require | |
[babashka.fs :as fs] | |
[babashka.process :refer [shell]] | |
[clojure.java.io :as io] | |
[clojure.pprint :as pp] | |
[clojure.string :as str] | |
[cognitect.transit :as transit])) | |
(defn transit2edn [file] | |
(with-open [rdr (io/input-stream (io/file file))] | |
(let [rdr (transit/reader rdr :json) | |
transit (transit/read rdr) | |
tmp-file (doto (fs/file (fs/temp-dir) (str (gensym))) | |
(fs/delete-on-exit))] | |
(spit tmp-file (with-out-str | |
(pp/pprint transit))) | |
tmp-file))) | |
(let [[$1 $2 $3 $4 $5 & $&] *command-line-args*] | |
(if (str/ends-with? $2 ".transit.json") | |
(apply shell "difft --language edn" $1 (transit2edn $2) $3 $4 (transit2edn $5) $&) | |
(apply shell "difft" *command-line-args*))) | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment