Merge pull request #18 from oug-t/feat/fugitive-support
feat: add integration with vim-fugitive
This commit is contained in:
commit
45df5cdc86
40
README.md
40
README.md
|
|
@ -1,4 +1,5 @@
|
||||||
<a id="readme-top"></a>
|
<a id="readme-top"></a>
|
||||||
|
|
||||||
<h1 align="center"><code>difi</code></h1>
|
<h1 align="center"><code>difi</code></h1>
|
||||||
<p align="center"><em>Review and refine Git diffs before you push</em></p>
|
<p align="center"><em>Review and refine Git diffs before you push</em></p>
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@
|
||||||
|
|
||||||
## Why difi?
|
## Why difi?
|
||||||
|
|
||||||
**git diff** shows changes. **difi** helps you *review* them.
|
**git diff** shows changes. **difi** helps you _review_ them.
|
||||||
|
|
||||||
- ⚡️ **Instant** — Built in Go. Launches immediately with no daemon or indexing.
|
- ⚡️ **Instant** — Built in Go. Launches immediately with no daemon or indexing.
|
||||||
- 🎨 **Structured** — A clean file tree and focused diffs for fast mental parsing.
|
- 🎨 **Structured** — A clean file tree and focused diffs for fast mental parsing.
|
||||||
|
|
@ -41,11 +42,13 @@ go install github.com/oug-t/difi/cmd/difi@latest
|
||||||
#### AUR (Arch Linux)
|
#### AUR (Arch Linux)
|
||||||
|
|
||||||
**Binary (pre-built):**
|
**Binary (pre-built):**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pikaur -S difi-bin
|
pikaur -S difi-bin
|
||||||
```
|
```
|
||||||
|
|
||||||
**Build from source:**
|
**Build from source:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pikaur -S difi
|
pikaur -S difi
|
||||||
```
|
```
|
||||||
|
|
@ -81,7 +84,27 @@ difi
|
||||||
|
|
||||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||||
|
|
||||||
## Neovim Integration
|
## Integrations
|
||||||
|
|
||||||
|
#### vim-fugitive
|
||||||
|
|
||||||
|
- **The "Unix philosophy" approach:** Uses the industry-standard Git wrapper to provide a robust, side-by-side editing experience.
|
||||||
|
- **Side-by-Side Editing:** Instantly opens a vertical split (:Gvdiffsplit!) against the index.
|
||||||
|
- **Merge Conflicts:** Automatically detects conflicts and opens a 3-way merge view for resolution.
|
||||||
|
- **Config**: Add the line below to if using **lazy.nvim**.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
"tpope/vim-fugitive",
|
||||||
|
cmd = { "Gvdiffsplit", "Git" }, -- Add this line
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
<p align="left">
|
||||||
|
<img src="https://img.shields.io/badge/Supports-vim--fugitive-4d4d4d?style=for-the-badge&logo=vim&logoColor=white" alt="Supports vim-fugitive" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
#### difi.nvim
|
||||||
|
|
||||||
Get the ultimate review experience with **[difi.nvim](https://github.com/oug-t/difi.nvim)**.
|
Get the ultimate review experience with **[difi.nvim](https://github.com/oug-t/difi.nvim)**.
|
||||||
|
|
||||||
|
|
@ -105,7 +128,9 @@ To use `difi` as a native git command (e.g., `git difi`), add it as an alias in
|
||||||
```bash
|
```bash
|
||||||
git config --global alias.difi '!difi'
|
git config --global alias.difi '!difi'
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can run it directly from git:
|
Now you can run it directly from git:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git difi
|
git difi
|
||||||
```
|
```
|
||||||
|
|
@ -121,6 +146,7 @@ go run cmd/difi/main.go
|
||||||
```
|
```
|
||||||
|
|
||||||
Contributions are especially welcome in:
|
Contributions are especially welcome in:
|
||||||
|
|
||||||
- diff.nvim rendering edge cases
|
- diff.nvim rendering edge cases
|
||||||
- UI polish and accessibility
|
- UI polish and accessibility
|
||||||
- Windows support
|
- Windows support
|
||||||
|
|
@ -143,13 +169,3 @@ Contributions are especially welcome in:
|
||||||
---
|
---
|
||||||
|
|
||||||
<p align="center"> Made with ❤️ by <a href="https://github.com/oug-t">oug-t</a> </p>
|
<p align="center"> Made with ❤️ by <a href="https://github.com/oug-t">oug-t</a> </p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package ui
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -225,13 +227,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m.selectedPath != "" {
|
if m.selectedPath != "" {
|
||||||
if i, ok := m.fileList.SelectedItem().(tree.TreeItem); ok && !i.IsDir {
|
line := 0
|
||||||
// proceed
|
if m.focus == FocusDiff {
|
||||||
|
line = git.CalculateFileLine(m.diffContent, m.diffCursor)
|
||||||
} else {
|
} else {
|
||||||
return m, nil
|
line = git.CalculateFileLine(m.diffContent, 0)
|
||||||
}
|
}
|
||||||
|
return m, openFugitive(m.selectedPath, line)
|
||||||
}
|
}
|
||||||
fallthrough
|
|
||||||
|
|
||||||
case "e":
|
case "e":
|
||||||
if m.selectedPath != "" {
|
if m.selectedPath != "" {
|
||||||
|
|
@ -246,7 +249,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
line = git.CalculateFileLine(m.diffContent, 0)
|
line = git.CalculateFileLine(m.diffContent, 0)
|
||||||
}
|
}
|
||||||
m.inputBuffer = ""
|
m.inputBuffer = ""
|
||||||
return m, git.OpenEditorCmd(m.selectedPath, line, m.targetBranch)
|
return m, openFugitive(m.selectedPath, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "z":
|
case "z":
|
||||||
|
|
@ -370,6 +373,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openFugitive(path string, line int) tea.Cmd {
|
||||||
|
lineArg := fmt.Sprintf("+%d", line)
|
||||||
|
c := exec.Command("nvim", lineArg, "-c", "Gvdiffsplit!", path)
|
||||||
|
c.Stdin = os.Stdin
|
||||||
|
c.Stdout = os.Stdout
|
||||||
|
c.Stderr = os.Stderr
|
||||||
|
return tea.ExecProcess(c, func(err error) tea.Msg {
|
||||||
|
return git.EditorFinishedMsg{}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) centerDiffCursor() {
|
func (m *Model) centerDiffCursor() {
|
||||||
halfScreen := m.diffViewport.Height / 2
|
halfScreen := m.diffViewport.Height / 2
|
||||||
targetOffset := m.diffCursor - halfScreen
|
targetOffset := m.diffCursor - halfScreen
|
||||||
|
|
@ -661,8 +675,6 @@ func (m Model) renderEmptyState(w, h int, statusMsg string) string {
|
||||||
guides,
|
guides,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use lipgloss.Place to center the content in the available space
|
|
||||||
// This automatically handles vertical and horizontal centering.
|
|
||||||
return lipgloss.Place(w, h, lipgloss.Center, lipgloss.Center, content)
|
return lipgloss.Place(w, h, lipgloss.Center, lipgloss.Center, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user