はじめに

この資料は Rust 製のコマンドラインツール difftastic について紹介するものです。

Rustの環境構築やツールのインストール方法については以下を参照してください

Rust開発環境を整える

difftastic について

difftasticは、30以上のプログラミング言語の構文に基づいてファイルを比較する構造差分ツールです。 コマンド名は difft です。

GitHub - Wilfred/difftastic: a structural diff that understands syntax 🟥🟩

デモ

https://github.com/Wilfred/difftastic/raw/master/img/js.png

サポートしているプログラミング言語

プログラミング言語 使用しているパーサー
Ada https://github.com/briot/tree-sitter-ada
Bash https://github.com/tree-sitter/tree-sitter-bash
C https://github.com/tree-sitter/tree-sitter-c
C++ https://github.com/tree-sitter/tree-sitter-cpp
C# https://github.com/tree-sitter/tree-sitter-c-sharp
Clojure https://github.com/sogaiu/tree-sitter-clojure
CMake https://github.com/uyha/tree-sitter-cmake
Common Lisp https://github.com/theHamsta/tree-sitter-commonlisp
Dart https://github.com/UserNobody14/tree-sitter-dart
Elixir https://github.com/elixir-lang/tree-sitter-elixir
Elm https://github.com/elm-tooling/tree-sitter-elm
Elvish https://github.com/ckafi/tree-sitter-elvish
Erlang https://github.com/WhatsApp/tree-sitter-erlang
Emacs Lisp https://github.com/Wilfred/tree-sitter-elisp
Gleam https://github.com/gleam-lang/tree-sitter-gleam
Go https://github.com/tree-sitter/tree-sitter-go
Hack https://github.com/slackhq/tree-sitter-hack
Hare https://git.sr.ht/~ecmma/tree-sitter-hare
Haskell https://github.com/tree-sitter/tree-sitter-haskell
Janet https://github.com/sogaiu/tree-sitter-janet-simple
Java https://github.com/tree-sitter/tree-sitter-java
JavaScript, JSX https://github.com/tree-sitter/tree-sitter-javascript
Julia https://github.com/tree-sitter/tree-sitter-julia
Kotlin https://github.com/fwcd/tree-sitter-kotlin
Lua https://github.com/nvim-treesitter/tree-sitter-lua
Make https://github.com/alemuller/tree-sitter-make
Nix https://github.com/cstrahan/tree-sitter-nix
OCaml https://github.com/tree-sitter/tree-sitter-ocaml
Perl https://github.com/ganezdragon/tree-sitter-perl
PHP https://github.com/tree-sitter/tree-sitter-php
Python https://github.com/tree-sitter/tree-sitter-python
QML https://github.com/yuja/tree-sitter-qmljs
R https://github.com/r-lib/tree-sitter-r
Racket https://github.com/6cdh/tree-sitter-racket
Ruby https://github.com/tree-sitter/tree-sitter-ruby
Rust https://github.com/tree-sitter/tree-sitter-rust (https://github.com/Wilfred/tree-sitter-rust/tree/non_special_token)
Scala https://github.com/tree-sitter/tree-sitter-scala
SQL https://github.com/m-novikov/tree-sitter-sql
Swift https://github.com/alex-pinkus/tree-sitter-swift
TypeScript, TSX https://github.com/tree-sitter/tree-sitter-typescript
Zig https://github.com/maxxnino/tree-sitter-zig

MIMEデータベース

difftastic は、MIMEデータベースが使用できる場合は、ファイルをより正確に検出するために使用します。Linux の場合は、file コマンドと同様なので、通常はインストール済みなはずです。 MIMEデータベースは XDG仕様で指定されているため、次のいずれかのパスに存在するはずです。

/usr/share/mime/magic/usr/local/share/mime/magic$HOME/.local/share/mime/magic

使用方法

difft [OPTIONS] OLD-PATH NEW-PATH

オプション