Skip to content

Commit

Permalink
feat: adds diffview.nvim support
Browse files Browse the repository at this point in the history
  • Loading branch information
agoodshort committed Mar 11, 2024
1 parent 8a4c49f commit 544ede7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,35 @@ require("telescope").setup({
git_cmd = "lazygit",
previewer = true,
terminal_id = 9,
diffview_keymap = "<C-d>",
},
},
})
```

### Extension Specs

| Property | Type | Default Value | Description |
|-------------|---------|---------------|-------------------------------------------|
| git_cmd | string? | "lazygit" | git TUI command of your choice |
| previewer | boolean | true | Preview submodule changes in Telescope |
| terminal_id | number? | 9 | Terminal ID toggleterm will use |
| Property | Type | Default Value | Description |
|-----------------|----------|---------------|-----------------------------------------------------------------|
| git_cmd | string? | "lazygit" | git TUI command of your choice |
| previewer | boolean? | true | Preview submodule changes in Telescope |
| terminal_id | number? | 9 | Terminal ID toggleterm will use |
| diffview_keymap | string? | "<C-d>" | Keymap to trigger `:diffviewOpen` for the highlighted submodule |

## Roadmap
## Plugin integration

- [ ] Keymap to trigger `:DiffView` for the highlighted submodule
- [ ] Support additional terminal plugins (e.g., [nvim-terminal](https://github.com/s1n7ax/nvim-terminal))
### nvim-unception

The extension integrates pretty well (at least from my personal experience) with [nvim-unception](https://github.com/samjwill/nvim-unception), if the same `terminal_id` value is used in both configurations. Example in [agoodshort's nvim-unception configuration](https://github.com/agoodshort/nvim/blob/e9e89782e124e3c666097edeb0603317b8e72320/lua/agoodshort/plugins/terminal/nvim-unception.lua#L11)

### diffview.nvim

## Remarks
If you have [diffview.nvim](https://github.com/sindrets/diffview.nvim), you can use the `diffview_keymap` to trigger `:diffviewOpen -C<path>` for the highlighted submodule.

The extension works well with [nvim-unception](https://github.com/samjwill/nvim-unception), if the same `terminal_id` value is used in both configurations. Example in [agoodshort's nvim-unception configuration](https://github.com/agoodshort/nvim/blob/e9e89782e124e3c666097edeb0603317b8e72320/lua/agoodshort/plugins/terminal/nvim-unception.lua#L11)
## Roadmap

- [ ] Support additional terminal plugins (e.g., [nvim-terminal](https://github.com/s1n7ax/nvim-terminal))
- [ ] Add the option to point `:diffviewOpen` to `origin/HEAD`

## Acknowledgements

Expand Down
16 changes: 15 additions & 1 deletion lua/telescope/_extensions/git_submodules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local setup_opts = {
git_cmd = "lazygit",
previewer = true,
terminal_id = 9,
diffview_keymap = "<C-d>",
}

local function open_git_tool(opts, selection)
Expand Down Expand Up @@ -187,14 +188,27 @@ local show_repos = function(opts)
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_buf, _)
attach_mappings = function(prompt_buf, map)
actions.select_default:replace(function()
-- for what ever reason any attempt to open an external window (such as lazygit)
-- shall be done after closing the buffer manually
actions.close(prompt_buf)

open_git_tool(opts, nil)
end)
local diffviewInstalled, _ = pcall(require, "diffview")
if diffviewInstalled then
map({ "i", "n" }, opts.diffview_keymap, function()
local selection = action_state.get_selected_entry().value -- picking the repo_name from the item received
local dir_name = vim.fn.substitute(vim.fn.getcwd(), "^.*/", "", "")
local dir = vim.fn.getcwd()
if selection ~= dir_name then
dir = dir .. "/" .. selection
end
actions.close(prompt_buf)
vim.cmd(("DiffviewOpen -C%s"):format(dir))
end)
end
return true
end,
previewer = previewer_config,
Expand Down

0 comments on commit 544ede7

Please sign in to comment.