Skip to content

Commit 6afecde

Browse files
committed
feat!: use vim.ui.select, telescope thus no longer hard dependency
`telescope` is still required for `.interactiveStaging()`, since it requires a preview, which `vim.ui.select` does not provide.
1 parent e95065c commit 6afecde

File tree

5 files changed

+35
-103
lines changed

5 files changed

+35
-103
lines changed

README.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@
66

77
Bundle of commands focused on swift and streamlined git operations.
88

9-
<!-- DEPRECATION 2025-03-03 -->
10-
## Breaking changes in v1.0
11-
- `dressing.nvim` and `nvim-notify` are **no longer dependencies**.
12-
- `telescope.nvim` is now a **required dependency**.
13-
- The `commit.insertIssuesOnHashSign` feature has been removed. Better issue
14-
insertion via plugins like [cmp-git](https://github.com/petertriho/cmp-git) or
15-
[blink-cmp-git](https://github.com/Kaiser-Yang/blink-cmp-git) now work there.
16-
- `smartCommit` was overhauled. Among other improvements, it now supports a
17-
commit body.
18-
19-
> [!NOTE]
20-
> If you want to keep using the previous version, without these breaking
21-
> changes, you can pin the tag `v0.9`:
22-
>
23-
> ```lua
24-
> -- lazy.nvim
25-
> {
26-
> "chrisgrieser/nvim-tinygit",
27-
> tag = "v0.9"
28-
> dependencies = "stevearc/dressing.nvim",
29-
> },
30-
> ```
31-
329
## Feature overview
3310

3411
<table>
@@ -95,9 +72,18 @@ Bundle of commands focused on swift and streamlined git operations.
9572
## Installation
9673
**Requirements**
9774
- nvim 0.10+
98-
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
99-
- `curl` for GitHub-related features
100-
- *optional*: Treesitter parser for syntax highlighting: `TSInstall gitcommit`
75+
- for interactive staging:
76+
[telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) for (PRs
77+
adding support for other pickers welcome)
78+
- for GitHub-related commands: `curl`
79+
- *recommended*: Treesitter parser for syntax highlighting: `TSInstall
80+
gitcommit`
81+
- *recommended*: a plugin implementing `vim.ui.select`, such as:
82+
* [snacks.picker](http://github.com/folke/snacks.nvim)
83+
* [mini.pick](http://github.com/echasnovski/mini.pick)
84+
* [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) with
85+
[telescope-ui-select](https://github.com/nvim-telescope/telescope-ui-select.nvim)
86+
* [fzf-lua](https://github.com/ibhagwan/fzf-lua)
10187

10288
```lua
10389
-- lazy.nvim
@@ -228,8 +214,10 @@ since the `:Tinygit` does not accept command-specific options and does not
228214
trigger visual-mode specific changes to the commands.
229215

230216
### Interactive staging
231-
- This command stages hunks, that is, *parts* of a file instead of the
232-
full file. It is roughly comparable to `git add -p`.
217+
- Interactive straging requires `telescope`. (PRs adding support for other
218+
pickers welcome.)
219+
- This command stages hunks, that is, *parts* of a file instead of the full
220+
file. It is roughly comparable to `git add -p`.
233221
- Use `<Space>` to (un)stage the hunk, `<CR>` to go to the hunk, or `<C-r` to
234222
reset the hunk (mappings customizable). Your regular `telescope` mappings also
235223
apply.
@@ -322,7 +310,7 @@ require("tinygit").undoLastCommitOrAmend()
322310

323311
### GitHub interaction
324312
**Search issues & PRs**
325-
- Requires `curl`.
313+
- The GitHub interaction commands all require `curl`.
326314

327315
```lua
328316
-- state: all|closed|open (default: all)

lua/tinygit/commands/commit.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,7 @@ function M.fixupCommit(opts)
252252
updateStatusline()
253253
end
254254

255-
require("tinygit.shared.picker").withTelescope(
256-
prompt,
257-
commits,
258-
commitFormatter,
259-
stylingFunc,
260-
onChoice
261-
)
255+
require("tinygit.shared.picker").pick(prompt, commits, commitFormatter, stylingFunc, onChoice)
262256
end
263257

264258
--------------------------------------------------------------------------------

lua/tinygit/commands/github.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,7 @@ function M.issuesAndPrs(opts)
157157
return ("%s #%s %s by %s"):format(icon, issue.number, issue.title, issue.user.login)
158158
end
159159

160-
require("tinygit.shared.picker").withTelescope(
161-
prompt,
162-
issues,
163-
issueListFormatter,
164-
stylingFunc,
165-
onChoice
166-
)
160+
require("tinygit.shared.picker").pick(prompt, issues, issueListFormatter, stylingFunc, onChoice)
167161
end
168162

169163
function M.openIssueUnderCursor()

lua/tinygit/commands/history.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,7 @@ local function selectFromCommits(commitList)
314314
end
315315
local onChoice = function(_, commitIdx) showDiff(commitIdx) end
316316

317-
require("tinygit.shared.picker").withTelescope(
318-
prompt,
319-
commits,
320-
commitFormatter,
321-
stylingFunc,
322-
onChoice
323-
)
317+
require("tinygit.shared.picker").pick(prompt, commits, commitFormatter, stylingFunc, onChoice)
324318
end
325319

326320
--------------------------------------------------------------------------------

lua/tinygit/shared/picker.lua

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
11
local M = {}
2-
3-
local u = require("tinygit.shared.utils")
42
--------------------------------------------------------------------------------
53

64
---@param prompt string
75
---@param items any[]
86
---@param itemFormatter fun(item: any): string
97
---@param stylingFunc fun()
108
---@param onChoice fun(item: any, index?: number)
11-
function M.withTelescope(prompt, items, itemFormatter, stylingFunc, onChoice)
12-
local installed, _ = pcall(require, "telescope")
13-
if not installed then
14-
u.notify("telescope.nvim is not installed.", "warn")
15-
return
16-
end
17-
18-
local finders = require("telescope.finders")
19-
local pickers = require("telescope.pickers")
20-
local telescopeConf = require("telescope.config").values
21-
local actionState = require("telescope.actions.state")
22-
local actions = require("telescope.actions")
23-
24-
-- INFO implement styling via `autocmd` instead of telescope's `entry_maker`,
25-
-- since the former is more generic, and can be used for potential other
26-
-- pickers in the future
27-
vim.api.nvim_create_autocmd("FileType", {
9+
function M.pick(prompt, items, itemFormatter, stylingFunc, onChoice)
10+
-- Add some basic styling & backdrop, if using `telescope` or `snacks.picker`
11+
local autocmd = vim.api.nvim_create_autocmd("FileType", {
2812
desc = "Tinygit: Styling for TelescopeResults",
2913
once = true,
30-
pattern = "TelescopeResults",
31-
callback = stylingFunc,
14+
pattern = { "TelescopeResults", "snacks_picker_list" },
15+
callback = function(ctx)
16+
vim.schedule(function() vim.api.nvim_buf_call(ctx.buf, stylingFunc) end)
17+
require("tinygit.shared.backdrop").new(ctx.buf)
18+
end,
3219
})
3320

34-
local telescopeOpts = {
35-
layout_strategy = "horizontal",
36-
layout_config = {
37-
horizontal = {
38-
width = { 0.9, max = 100 },
39-
height = { 0.6, max = 40 },
40-
},
41-
},
42-
}
43-
44-
-- DOCS https://github.com/nvim-telescope/telescope.nvim/blob/master/developers.md#first-picker
45-
pickers
46-
.new(telescopeOpts, {
47-
prompt_title = prompt,
48-
sorter = telescopeConf.generic_sorter {},
49-
finder = finders.new_table {
50-
results = items,
51-
entry_maker = function(item)
52-
local display = itemFormatter(item)
53-
return { value = item, display = display, ordinal = display }
54-
end,
55-
},
56-
attach_mappings = function(promptBufnr, _)
57-
actions.select_default:replace(function()
58-
actions.close(promptBufnr)
59-
local selection = actionState.get_selected_entry()
60-
onChoice(selection.value, selection.index)
61-
end)
62-
return true -- `true` = keep other mappings from the user
63-
end,
64-
})
65-
:find()
21+
vim.ui.select(items, {
22+
prompt = prompt,
23+
format_item = itemFormatter,
24+
}, function(selection, index)
25+
if selection then onChoice(selection, index) end
26+
vim.api.nvim_del_autocmd(autocmd)
27+
end)
6628
end
6729

6830
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)