Semantic diff
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: renae sdiff -> adiff

+3 -173
+3 -173
README.md
··· 1 - # adiff 2 - 3 - A semantic, side-by-side diff viewer for the terminal with `$EDITOR` support. 4 - 5 - Unlike traditional diff tools, adiff uses [tree-sitter](https://tree-sitter.github.io/tree-sitter/) to parse source files into ASTs and diffs at the token level. This means pure formatting changes — re-indented blocks, reformatted function signatures, whitespace normalization — are shown as equal, while genuine logic changes are clearly highlighted. 6 - 7 - ![adiff screenshot](docs/screenshot.png) 8 - 9 - ## Features 10 - 11 - - **Semantic diff** — tree-sitter token-level diffing ignores style-only changes 12 - - **Syntax highlighting** — per-language color via [Chroma](https://github.com/alecthomas/chroma) 13 - - **Live file watching** — press `e` to open the new file in `$EDITOR`; adiff watches for saves and reloads automatically 14 - - **Vim keybindings** — `j`/`k`, `g`/`G`, `n`/`p` for change navigation 15 - - **Themeable** — TOML theme files with full colour control; `nord` built-in 16 - 17 - ### Semantic Supported languages 18 - 19 - Bash, C, C++, Go, JavaScript, JSON, Nix, Python, Ruby, Rust, TypeScript 20 - 21 - ### Supported languages 22 - 23 - All languages without semantic support are supported with traditional text diffs 24 - 25 - ## Installation 26 - 27 - ### Nix (flake) 28 - 29 - ```nix 30 - inputs.adiff.url = "git+https://tangled.org/adriano.tngl.sh/adiff"; 31 - ``` 32 - 33 - Then add `inputs.adiff.packages.${system}.default` to your packages, or use the provided overlay. 34 - 35 - **Direct package reference** (home-manager / NixOS `environment.systemPackages`): 36 - 37 - ```nix 38 - home.packages = [ inputs.adiff.packages.${pkgs.system}.default ]; 39 - ``` 40 - 41 - **Overlay** — adds `pkgs.adiff` to your package set: 42 - 43 - ```nix 44 - nixpkgs.overlays = [ inputs.adiff.overlays.default ]; 45 - 46 - # Then reference it like any nixpkgs package: 47 - home.packages = [ pkgs.adiff ]; 48 - ``` 49 - 50 - In a NixOS or home-manager flake this typically looks like: 51 - 52 - ```nix 53 - { 54 - inputs = { 55 - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 56 - home-manager.url = "github:nix-community/home-manager"; 57 - adiff.url = "git+https://tangled.org/adriano.tngl.sh/adiff"; 58 - }; 59 - 60 - outputs = { nixpkgs, home-manager, adiff, ... }: { 61 - homeConfigurations.yourname = home-manager.lib.homeManagerConfiguration { 62 - pkgs = import nixpkgs { 63 - system = "x86_64-linux"; 64 - overlays = [ adiff.overlays.default ]; 65 - }; 66 - modules = [ 67 - ({ pkgs, ... }: { home.packages = [ pkgs.adiff ]; }) 68 - ]; 69 - }; 70 - }; 71 - } 72 - ``` 73 - 74 - ## Usage 75 - 76 - ``` 77 - adiff [flags] <old-file> <new-file> 78 - ``` 79 - 80 - | Flag | Default | Description | 81 - |------|---------|-------------| 82 - | `-theme` | `nord` | Theme name or path to a `.toml` file | 83 - 84 - ### Keybindings 85 - 86 - | Key | Action | 87 - |-----|--------| 88 - | `j` / `k` | Move down / up | 89 - | `n` / `p` | Jump to next / previous change | 90 - | `g` / `G` | Jump to top / bottom | 91 - | `s` | Toggle semantic ↔ text diff mode | 92 - | `e` | Open new file in `$EDITOR`; diff reloads on save | 93 - | `q` | Quit | 94 - 95 - ## Diff modes 96 - 97 - **Semantic mode** (default) uses the tree-sitter AST to identify which tokens actually changed. Adjacent removed/added line blocks where all tokens are identical are collapsed into equal (unhighlighted) lines. Only lines containing genuinely changed tokens are highlighted. 98 - 99 - **Text mode** falls back to a standard line-level diff with no AST involvement. Toggle between modes with `s`. 100 - 101 - ## Themes 102 - 103 - Themes are TOML files. adiff searches for themes in this order: 104 - 105 - 1. Literal path (if the value contains `/` or ends in `.toml`) 106 - 2. `~/.config/adiff/themes/<name>.toml` 107 - 3. Built-in `nord` 108 - 109 - ### Theme format 110 - 111 - ```toml 112 - [meta] 113 - name = "mytheme" 114 - description = "My custom theme" 115 - author = "you" 116 - 117 - [chroma] 118 - style = "nord" # any Chroma style name 119 - 120 - [diff] 121 - added_bg = "#2E4034" 122 - added_fg = "#A3BE8C" 123 - removed_bg = "#3D1F1F" 124 - removed_fg = "#BF616A" 125 - equal_fg = "#D8DEE9" 126 - header_fg = "#88C0D0" 127 - line_number_fg = "#4C566A" 128 - status_fg = "#5E81AC" 129 - help_fg = "#4C566A" 130 - cursor_symbol = "▶" 131 - ``` 132 - 133 - Place custom themes at `~/.config/adiff/themes/<name>.toml` and reference them with `-theme <name>`. 134 - 135 - ## hookable integration 136 - 137 - [hookable](https://tangled.org/adriano.tngl.sh/hookable) is a Claude Code hook runner that exposes tool call inputs as environment variables and forwards them to an arbitrary command. adiff reads these variables natively, so it can be dropped in as the `--cmd` to preview file changes before Claude applies them. 138 - 139 - When invoked with no file arguments and `HOOKABLE_TOOL_NAME` is set, adiff constructs the before/after diff automatically: 140 - 141 - | Tool | Before | After | 142 - |------|--------|-------| 143 - | `Edit` | Current file on disk | File with `old_string` replaced by `new_string` | 144 - | `Write` | Current file on disk (empty if new) | Incoming content | 145 - 146 - ### Claude Code hook configuration 147 - 148 - Add to `~/.claude/settings.json`: 149 - 150 - ```json 151 - { 152 - "hooks": { 153 - "PreToolUse": [ 154 - { 155 - "matcher": "Edit", 156 - "hooks": [{"type": "command", "command": "hookable --interactive --no-exit-code --cmd 'adiff -i'"}] 157 - }, 158 - { 159 - "matcher": "Write", 160 - "hooks": [{"type": "command", "command": "hookable --interactive --no-exit-code --cmd 'adiff -i'"}] 161 - } 162 - ] 163 - } 164 - } 165 - ``` 166 - 167 - `--interactive` runs adiff under a PTY so the full TUI renders. `--no-exit-code` tells hookable to ignore adiff's exit code and always wait for a keypress — press `y` to allow the change or `n` to deny it. 1 + # sdiff 168 2 169 - ## Development 3 + `sdiff` has been renamed [adiff](https://tangled.org/adriano.tngl.sh/adiff/), but Tangled does not support repo renames. 170 4 171 - ```sh 172 - nix develop # CGO-aware dev shell 173 - go test ./... # run tests 174 - nix build # hermetic build → ./result/bin/adiff 175 - ``` 5 + Now at: [https://tangled.org/adriano.tngl.sh/adiff/](https://tangled.org/adriano.tngl.sh/adiff/)