git-diff-view 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jeff Haynie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,48 +1,94 @@
1
1
  # git-diff-view
2
2
 
3
- A beautiful git diff viewer that opens in your browser, powered by [@pierre/diffs](https://diffs.com/).
3
+ A beautiful, browser-based git diff viewer with syntax highlighting and automatic dark/light theme detection.
4
4
 
5
- ## Features
5
+ ![git-diff-view screenshot](screenshot.png)
6
6
 
7
- - 🎨 **Auto theme detection** - matches your system light/dark mode
8
- - 📊 **Stacked (unified) layout** - easy to read diffs
9
- - 📏 **Styled bars** - visual indicators for additions/deletions
10
- - 🔢 **Line numbers** - always visible
11
- - **Word-level highlighting** - see exactly what changed
12
- - 📁 **Multi-file support** - all changes in one view
7
+ ## Why git-diff-view?
8
+
9
+ Terminal diffs are hard to read. `git-diff-view` opens your diffs in a beautiful browser interface with:
10
+
11
+ - **Word-level highlighting** see exactly which characters changed, not just which lines
12
+ - **Automatic theme detection** seamlessly matches your system's light or dark mode
13
+ - **Unified diff layout** — familiar, easy-to-scan format with colored addition/deletion bars
14
+ - **Multi-file support** — review all your changes in a single scrollable view
15
+ - **Zero configuration** — works out of the box
16
+
17
+ Powered by [@pierre/diffs](https://diffs.com/).
18
+
19
+ ---
13
20
 
14
21
  ## Installation
15
22
 
23
+ ### Prerequisites
24
+
25
+ - [Bun](https://bun.sh) — install with `curl -fsSL https://bun.sh/install | bash`
26
+ - macOS (uses native `open` command and theme detection)
27
+
28
+ ### Quick Start
29
+
30
+ ```bash
31
+ # Install globally
32
+ bun install -g git-diff-view
33
+
34
+ # Install the git alias
35
+ git-diff-view install
36
+ ```
37
+
38
+ Or with npm:
39
+
16
40
  ```bash
17
- bun install
18
- ./index.ts install
41
+ npm install -g git-diff-view
42
+ git-diff-view install
19
43
  ```
20
44
 
21
- This installs a global git alias `dv`.
45
+ That's it. You now have a `git dv` command available in any repository.
46
+
47
+ ---
22
48
 
23
49
  ## Usage
24
50
 
51
+ ### As a git alias (recommended)
52
+
53
+ After installation, use `git dv` anywhere you'd use `git diff`:
54
+
25
55
  ```bash
26
- git dv # unstaged changes
27
- git dv --staged # staged changes
28
- git dv HEAD~3 # last 3 commits
29
- git dv main..HEAD # compare branches
30
- git dv -- file.ts # specific file
56
+ git dv # View unstaged changes
57
+ git dv --staged # View staged changes
58
+ git dv HEAD~1 # View last commit
59
+ git dv HEAD~3 # View last 3 commits
60
+ git dv main..feature # Compare branches
61
+ git dv -- src/app.ts # View changes to a specific file
31
62
  ```
32
63
 
33
- ## Commands
64
+ ### Standalone commands
34
65
 
35
66
  ```bash
36
- ./index.ts install # install git alias
37
- ./index.ts uninstall # remove git alias
38
- ./index.ts run # view diff (used by alias)
39
- ./index.ts --help # show help
67
+ ./index.ts install # Install the git dv alias
68
+ ./index.ts uninstall # Remove the git dv alias
69
+ ./index.ts run # Run the diff viewer directly
70
+ ./index.ts --help # Show help
40
71
  ```
41
72
 
42
- ## Requirements
73
+ ---
74
+
75
+ ## How It Works
76
+
77
+ 1. `git dv` captures the output of `git diff` with your arguments
78
+ 2. A local server spins up and parses the diff
79
+ 3. Your browser opens to a React-powered diff viewer
80
+ 4. The server automatically shuts down after 3 seconds
81
+
82
+ ---
83
+
84
+ ## Uninstall
85
+
86
+ ```bash
87
+ git-diff-view uninstall
88
+ bun remove -g git-diff-view
89
+ ```
43
90
 
44
- - [Bun](https://bun.sh) runtime
45
- - macOS (for `open` command and theme detection)
91
+ ---
46
92
 
47
93
  ## License
48
94
 
package/frontend.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FileDiff } from "@pierre/diffs/react";
2
2
  import { parsePatchFiles, type FileDiffMetadata } from "@pierre/diffs";
3
- import React, { useEffect, useState } from "react";
3
+ import React, { useEffect, useState, type ReactNode } from "react";
4
4
  import { createRoot } from "react-dom/client";
5
5
 
6
6
  interface DiffData {
@@ -8,10 +8,113 @@ interface DiffData {
8
8
  theme: "pierre-dark" | "pierre-light";
9
9
  }
10
10
 
11
+ type DiffStyle = "unified" | "split";
12
+
13
+ interface IconProps {
14
+ size?: number;
15
+ }
16
+
17
+ function IconDiffSplit({ size = 16 }: IconProps) {
18
+ return (
19
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
20
+ <path d="M14 0H8.5v16H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2m-1.5 6.5v1h1a.5.5 0 0 1 0 1h-1v1a.5.5 0 0 1-1 0v-1h-1a.5.5 0 0 1 0-1h1v-1a.5.5 0 0 1 1 0" />
21
+ <path d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h5.5V0zm.5 7.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1 0-1" opacity={0.3} />
22
+ </svg>
23
+ );
24
+ }
25
+
26
+ function IconDiffUnified({ size = 16 }: IconProps) {
27
+ return (
28
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
29
+ <path fillRule="evenodd" d="M16 14a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V8.5h16zm-8-4a.5.5 0 0 0-.5.5v1h-1a.5.5 0 0 0 0 1h1v1a.5.5 0 0 0 1 0v-1h1a.5.5 0 0 0 0-1h-1v-1A.5.5 0 0 0 8 10" clipRule="evenodd" />
30
+ <path fillRule="evenodd" d="M14 0a2 2 0 0 1 2 2v5.5H0V2a2 2 0 0 1 2-2zM6.5 3.5a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1z" clipRule="evenodd" opacity={0.4} />
31
+ </svg>
32
+ );
33
+ }
34
+
35
+ function IconCodeStyleBars({ size = 16 }: IconProps) {
36
+ return (
37
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
38
+ <g opacity={0.4}>
39
+ <path d="M4.25 13a.75.75 0 0 1 0 1.5h-1.5a.75.75 0 0 1 0-1.5zM6.25 1a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1 0-1.5zM4 4.75A.75.75 0 0 1 4.75 4h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 4 4.75" />
40
+ </g>
41
+ <path fillRule="evenodd" d="M4 7.75A.75.75 0 0 1 4.75 7h10.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 7.75" clipRule="evenodd" />
42
+ <path d="M4 10.75a.75.75 0 0 1 .75-.75h8.5a.75.75 0 0 1 0 1.5h-8.5a.75.75 0 0 1-.75-.75M0 7.5A.5.5 0 0 1 .5 7h1a.5.5 0 0 1 .5.5V11a.5.5 0 0 1-.5.5h-1A.5.5 0 0 1 0 11z" />
43
+ </svg>
44
+ );
45
+ }
46
+
47
+ function IconCodeStyleBg({ size = 16 }: IconProps) {
48
+ return (
49
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
50
+ <path d="M0 2.25a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H.75A.75.75 0 0 1 0 2.25" opacity={0.4} />
51
+ <path fillRule="evenodd" d="M15 5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zM2.5 9a.5.5 0 0 0 0 1h8a.5.5 0 0 0 0-1zm0-2a.5.5 0 0 0 0 1h11a.5.5 0 0 0 0-1z" clipRule="evenodd" />
52
+ <path d="M0 14.75A.75.75 0 0 1 .75 14h5.5a.75.75 0 0 1 0 1.5H.75a.75.75 0 0 1-.75-.75" opacity={0.4} />
53
+ </svg>
54
+ );
55
+ }
56
+
57
+ function IconChevronDown({ size = 16 }: IconProps) {
58
+ return (
59
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
60
+ <path fillRule="evenodd" d="M4.22 5.72a.75.75 0 0 1 1.06 0L8 8.44l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 6.78a.75.75 0 0 1 0-1.06z" clipRule="evenodd" />
61
+ </svg>
62
+ );
63
+ }
64
+
65
+ function IconChevronRight({ size = 16 }: IconProps) {
66
+ return (
67
+ <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" width={size} height={size}>
68
+ <path fillRule="evenodd" d="M5.72 11.78a.75.75 0 0 1 0-1.06L8.44 8 5.72 5.28a.75.75 0 0 1 1.06-1.06l3.25 3.25a.75.75 0 0 1 0 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0z" clipRule="evenodd" />
69
+ </svg>
70
+ );
71
+ }
72
+
73
+ interface IconButtonProps {
74
+ onClick: () => void;
75
+ icon: ReactNode;
76
+ title: string;
77
+ }
78
+
79
+ function IconButton({ onClick, icon, title }: IconButtonProps) {
80
+ return (
81
+ <button
82
+ onClick={onClick}
83
+ title={title}
84
+ style={{
85
+ background: "none",
86
+ border: "none",
87
+ cursor: "pointer",
88
+ padding: 4,
89
+ borderRadius: 4,
90
+ display: "flex",
91
+ alignItems: "center",
92
+ justifyContent: "center",
93
+ opacity: 0.7,
94
+ color: "inherit",
95
+ }}
96
+ onMouseEnter={(e) => (e.currentTarget.style.opacity = "1")}
97
+ onMouseLeave={(e) => (e.currentTarget.style.opacity = "0.7")}
98
+ >
99
+ {icon}
100
+ </button>
101
+ );
102
+ }
103
+
11
104
  const App = () => {
12
105
  const [data, setData] = useState<DiffData | null>(null);
13
106
  const [files, setFiles] = useState<FileDiffMetadata[]>([]);
14
107
  const [error, setError] = useState<string | null>(null);
108
+ const [diffStyle, setDiffStyle] = useState<DiffStyle>("unified");
109
+ const [disableBackground, setDisableBackground] = useState(false);
110
+ const [collapsedFiles, setCollapsedFiles] = useState<Record<number, boolean>>({});
111
+
112
+ const toggleCollapse = (index: number) => {
113
+ setCollapsedFiles((prev) => ({
114
+ ...prev,
115
+ [index]: !prev[index],
116
+ }));
117
+ };
15
118
 
16
119
  useEffect(() => {
17
120
  fetch("/api/diff")
@@ -37,20 +140,46 @@ const App = () => {
37
140
  return <div style={{ color: "#888", padding: 20 }}>No changes</div>;
38
141
  }
39
142
 
143
+ const renderHeaderMetadata = (index: number) => (
144
+ <div style={{ display: "flex", alignItems: "center", gap: 4, marginRight: -4 }}>
145
+ <IconButton
146
+ onClick={() => setDiffStyle((c) => (c === "split" ? "unified" : "split"))}
147
+ icon={diffStyle === "split" ? <IconDiffSplit size={16} /> : <IconDiffUnified size={16} />}
148
+ title={diffStyle === "split" ? "Switch to unified" : "Switch to split"}
149
+ />
150
+ <IconButton
151
+ onClick={() => setDisableBackground((c) => !c)}
152
+ icon={disableBackground ? <IconCodeStyleBars size={16} /> : <IconCodeStyleBg size={16} />}
153
+ title={disableBackground ? "Enable background" : "Disable background"}
154
+ />
155
+ <IconButton
156
+ onClick={() => toggleCollapse(index)}
157
+ icon={collapsedFiles[index] ? <IconChevronRight size={16} /> : <IconChevronDown size={16} />}
158
+ title={collapsedFiles[index] ? "Expand" : "Collapse"}
159
+ />
160
+ </div>
161
+ );
162
+
40
163
  return (
41
164
  <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
42
- {files.map((file, i) => (
43
- <FileDiff
44
- key={i}
45
- fileDiff={file}
46
- options={{
47
- theme: data.theme,
48
- diffStyle: "unified",
49
- diffIndicators: "bars",
50
- lineDiffType: "word",
51
- }}
52
- />
53
- ))}
165
+ {files.map((file, i) => {
166
+ const isCollapsed = collapsedFiles[i] ?? false;
167
+ return (
168
+ <FileDiff
169
+ key={`${i}-${isCollapsed}`}
170
+ fileDiff={file}
171
+ options={{
172
+ theme: data.theme,
173
+ diffStyle,
174
+ diffIndicators: "bars",
175
+ lineDiffType: "word",
176
+ disableBackground,
177
+ unsafeCSS: isCollapsed ? "[data-code] { display: none; }" : "",
178
+ }}
179
+ renderHeaderMetadata={() => renderHeaderMetadata(i)}
180
+ />
181
+ );
182
+ })}
54
183
  </div>
55
184
  );
56
185
  };
package/index.ts CHANGED
@@ -75,18 +75,14 @@ const run = async (args: string[]) => {
75
75
  headers: { "Content-Type": "application/json" },
76
76
  }),
77
77
  },
78
- development: {
79
- hmr: true,
80
- },
81
78
  });
82
79
 
83
80
  const url = `http://localhost:${server.port}`;
84
- console.log(`Opening diff at ${url}`);
85
-
86
- await $`open ${url}`;
81
+ await $`open ${url}`.quiet();
87
82
 
88
83
  await Bun.sleep(3000);
89
84
  server.stop();
85
+ process.exit(0);
90
86
  };
91
87
 
92
88
  const showHelp = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-diff-view",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/CLAUDE.md DELETED
@@ -1,106 +0,0 @@
1
-
2
- Default to using Bun instead of Node.js.
3
-
4
- - Use `bun <file>` instead of `node <file>` or `ts-node <file>`
5
- - Use `bun test` instead of `jest` or `vitest`
6
- - Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
7
- - Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
8
- - Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
9
- - Use `bunx <package> <command>` instead of `npx <package> <command>`
10
- - Bun automatically loads .env, so don't use dotenv.
11
-
12
- ## APIs
13
-
14
- - `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
15
- - `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
16
- - `Bun.redis` for Redis. Don't use `ioredis`.
17
- - `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
18
- - `WebSocket` is built-in. Don't use `ws`.
19
- - Prefer `Bun.file` over `node:fs`'s readFile/writeFile
20
- - Bun.$`ls` instead of execa.
21
-
22
- ## Testing
23
-
24
- Use `bun test` to run tests.
25
-
26
- ```ts#index.test.ts
27
- import { test, expect } from "bun:test";
28
-
29
- test("hello world", () => {
30
- expect(1).toBe(1);
31
- });
32
- ```
33
-
34
- ## Frontend
35
-
36
- Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
37
-
38
- Server:
39
-
40
- ```ts#index.ts
41
- import index from "./index.html"
42
-
43
- Bun.serve({
44
- routes: {
45
- "/": index,
46
- "/api/users/:id": {
47
- GET: (req) => {
48
- return new Response(JSON.stringify({ id: req.params.id }));
49
- },
50
- },
51
- },
52
- // optional websocket support
53
- websocket: {
54
- open: (ws) => {
55
- ws.send("Hello, world!");
56
- },
57
- message: (ws, message) => {
58
- ws.send(message);
59
- },
60
- close: (ws) => {
61
- // handle close
62
- }
63
- },
64
- development: {
65
- hmr: true,
66
- console: true,
67
- }
68
- })
69
- ```
70
-
71
- HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
72
-
73
- ```html#index.html
74
- <html>
75
- <body>
76
- <h1>Hello, world!</h1>
77
- <script type="module" src="./frontend.tsx"></script>
78
- </body>
79
- </html>
80
- ```
81
-
82
- With the following `frontend.tsx`:
83
-
84
- ```tsx#frontend.tsx
85
- import React from "react";
86
- import { createRoot } from "react-dom/client";
87
-
88
- // import .css files directly and it works
89
- import './index.css';
90
-
91
- const root = createRoot(document.body);
92
-
93
- export default function Frontend() {
94
- return <h1>Hello, world!</h1>;
95
- }
96
-
97
- root.render(<Frontend />);
98
- ```
99
-
100
- Then, run index.ts
101
-
102
- ```sh
103
- bun --hot ./index.ts
104
- ```
105
-
106
- For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.