Skip to content

Commit 491fb59

Browse files
authored
feat(git_status): add FzfxGStatus commands, add git-delta support (#358)
* feat(git_status): add FzfxGStatus commands * feat(git_status): add setqflist for git status * fix(prompt): use 'Git' as prefix instead of 'G' * feat(git_status): support actions * feat(git_status): support delta * perf(test): add tests * chore * chore * chore * chore * chore * chore * chore * chore * chore * chore * chore * chore * chore * chore * docs(git_status): add FzfxGStatus commands * fix(git_status): descriptions * feat(git_commits): add git delta support * docs(depends): wording * perf(test): add tests * docs: wording * feat(git_blame): add git delta support * docs: wording * docs * docs * docs * docs * chore * chore * fix(lint): luacheck * fix(delta): correctly set terminal width
1 parent a847027 commit 491fb59

File tree

10 files changed

+621
-98
lines changed

10 files changed

+621
-98
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
- Press `CTRL-U`/`CTRL-W` to switch between workspace/current folder mode.
3232
- Use `V`/`W`/`P` variants (visual selection, cursor word, yank text).
3333
- Press `ESC` to quit, `ENTER` to open file.
34+
- [ ] FzfxGStatus
35+
- Press `CTRL-N`/`CTRL-P` to move down/up and preview contents.
36+
- Press `CTRL-U`/`CTRL-W` to switch between workspace/current folder mode.
37+
- Use `V`/`W`/`P` variants (visual selection, cursor word, yank text).
38+
- Press `ESC` to quit, `ENTER` to open file.
3439
- [ ] FzfxGBranches
3540
- Press `CTRL-N`/`CTRL-P` to move down/up and preview contents.
3641
- Press `CTRL-R`/`CTRL-O` to switch between local/remote branches.

README.md

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ https://github.com/linrongbin16/fzfx.nvim/assets/6496887/aa5ef18c-26b4-4a93-bd0c
7070
- [Nerd fonts](https://www.nerdfonts.com/) (optional for icons).
7171
- [rg](https://github.com/BurntSushi/ripgrep) (optional for **live grep**, by default use [grep](https://man7.org/linux/man-pages/man1/grep.1.html)).
7272
- [fd](https://github.com/sharkdp/fd) (optional for **files**, by default use [find](https://man7.org/linux/man-pages/man1/find.1.html)).
73-
- [bat](https://github.com/sharkdp/bat) (optional for preview files, e.g. the right side of **live grep**, **files**, by default use [cat](https://man7.org/linux/man-pages/man1/cat.1.html)).
74-
- [git](https://git-scm.com/) (optional for **git** commands).
75-
- [eza](https://github.com/eza-community/eza) (optional for **file explorer** commands, by default use [ls](https://man7.org/linux/man-pages/man1/ls.1.html)), [echo](https://man7.org/linux/man-pages/man1/echo.1p.html) (optional for **file explorer** commands, print current directory path).
73+
- [bat](https://github.com/sharkdp/bat) (optional for preview files, by default use [cat](https://man7.org/linux/man-pages/man1/cat.1.html)).
74+
- [git](https://git-scm.com/) (optional for **git** commands), [delta](https://github.com/dandavison/delta) (optional for preview **git diff**, **git show**).
75+
- [eza](https://github.com/eza-community/eza) (optional for **file explorer** commands, by default use [ls](https://man7.org/linux/man-pages/man1/ls.1.html)), [echo](https://man7.org/linux/man-pages/man1/echo.1p.html) (optional for preview **file explorer** cwd).
76+
- [echo](https://man7.org/linux/man-pages/man1/echo.1p.html) (mandatory for vim **commands**, **keymaps** commands).
7677

77-
> Note: `grep`, `find`, `cat`, etc are unix/linux builtin commands, while on Windows we don't have a builtin shell environment, so install rust commands such as `rg`, `fd`, `bat`, etc should be a better choice, while still recommend to [install linux shell commands on Windows](#windows) since utils like **echo** **sleep** are often used by somewhere.
78+
> Note: `grep`, `find`, `cat`, etc are unix/linux builtin commands, while on Windows we don't have a builtin shell environment, so install rust commands such as `rg`, `fd`, `bat`, etc should be a better choice, while still recommend to [install linux shell commands on Windows](#windows) since utils like **echo**, **sleep** are often used by somewhere.
7879
7980
### Windows
8081

@@ -262,7 +263,7 @@ Commands are named following below rules:
262263
- `alt-p`: toggle preview.
263264
- `ctrl-f`: preview half page down.
264265
- `ctrl-b`: preview half page up.
265-
- Multi keys
266+
- Select keys
266267
- `ctrl-e`: toggle select.
267268
- `ctrl-a`: toggle select all.
268269

@@ -279,7 +280,7 @@ Commands are named following below rules:
279280
<tr>
280281
<th>Command</th>
281282
<th>Mode</th>
282-
<th>Multi Keys</th>
283+
<th>Select Keys</th>
283284
<th>Preview Keys</th>
284285
</tr>
285286
</thead>
@@ -314,7 +315,7 @@ Commands are named following below rules:
314315
<tr>
315316
<th>Command</th>
316317
<th>Mode</th>
317-
<th>Multi Keys</th>
318+
<th>Select Keys</th>
318319
<th>Preview Keys</th>
319320
</tr>
320321
</thead>
@@ -352,7 +353,7 @@ Commands are named following below rules:
352353
<tr>
353354
<th>Command</th>
354355
<th>Mode</th>
355-
<th>Multi Keys</th>
356+
<th>Select Keys</th>
356357
<th>Preview Keys</th>
357358
</tr>
358359
</thead>
@@ -390,7 +391,7 @@ Commands are named following below rules:
390391
<tr>
391392
<th>Command</th>
392393
<th>Mode</th>
393-
<th>Multi Keys</th>
394+
<th>Select Keys</th>
394395
<th>Preview Keys</th>
395396
</tr>
396397
</thead>
@@ -416,6 +417,42 @@ Commands are named following below rules:
416417
</tbody>
417418
</table>
418419

420+
- Git Status (Changed Files)
421+
422+
> 1. Use `ctrl-q` to send selected lines to quickfix window and quit.
423+
> 2. Current directory variant is named with `C` suffix.
424+
425+
<table>
426+
<thead>
427+
<tr>
428+
<th>Command</th>
429+
<th>Mode</th>
430+
<th>Select Keys</th>
431+
<th>Preview Keys</th>
432+
</tr>
433+
</thead>
434+
<tbody>
435+
<tr>
436+
<td>FzfxGStatus(C)</td>
437+
<td>N</td>
438+
<td rowspan="4">Yes</td>
439+
<td rowspan="4">Yes</td>
440+
</tr>
441+
<tr>
442+
<td>FzfxGStatus(C)V</td>
443+
<td>V</td>
444+
</tr>
445+
<tr>
446+
<td>FzfxGStatus(C)W</td>
447+
<td>N</td>
448+
</tr>
449+
<tr>
450+
<td>FzfxGStatus(C)P</td>
451+
<td>N</td>
452+
</tr>
453+
</tbody>
454+
</table>
455+
419456
- Git Branches
420457

421458
> 1. Use `enter` to checkout branch.
@@ -426,7 +463,7 @@ Commands are named following below rules:
426463
<tr>
427464
<th>Command</th>
428465
<th>Mode</th>
429-
<th>Multi Keys</th>
466+
<th>Select Keys</th>
430467
<th>Preview Keys</th>
431468
</tr>
432469
</thead>
@@ -461,7 +498,7 @@ Commands are named following below rules:
461498
<tr>
462499
<th>Command</th>
463500
<th>Mode</th>
464-
<th>Multi Keys</th>
501+
<th>Select Keys</th>
465502
<th>Preview Keys</th>
466503
</tr>
467504
</thead>
@@ -496,7 +533,7 @@ Commands are named following below rules:
496533
<tr>
497534
<th>Command</th>
498535
<th>Mode</th>
499-
<th>Multi Keys</th>
536+
<th>Select Keys</th>
500537
<th>Preview Keys</th>
501538
</tr>
502539
</thead>
@@ -531,7 +568,7 @@ Commands are named following below rules:
531568
<tr>
532569
<th>Command</th>
533570
<th>Mode</th>
534-
<th>Multi Keys</th>
571+
<th>Select Keys</th>
535572
<th>Preview Keys</th>
536573
</tr>
537574
</thead>
@@ -566,7 +603,7 @@ Commands are named following below rules:
566603
<tr>
567604
<th>Command</th>
568605
<th>Mode</th>
569-
<th>Multi Keys</th>
606+
<th>Select Keys</th>
570607
<th>Preview Keys</th>
571608
</tr>
572609
</thead>
@@ -605,7 +642,7 @@ Commands are named following below rules:
605642
<tr>
606643
<th>Command</th>
607644
<th>Mode</th>
608-
<th>Multi Keys</th>
645+
<th>Select Keys</th>
609646
<th>Preview Keys</th>
610647
</tr>
611648
</thead>
@@ -643,7 +680,7 @@ Commands are named following below rules:
643680
<tr>
644681
<th>Command</th>
645682
<th>Mode</th>
646-
<th>Multi Keys</th>
683+
<th>Select Keys</th>
647684
<th>Preview Keys</th>
648685
</tr>
649686
</thead>
@@ -678,7 +715,7 @@ Commands are named following below rules:
678715
<tr>
679716
<th>Command</th>
680717
<th>Mode</th>
681-
<th>Multi Keys</th>
718+
<th>Select Keys</th>
682719
<th>Preview Keys</th>
683720
</tr>
684721
</thead>

lua/fzfx.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ local function setup(options)
5656

5757
-- git
5858
general.setup("git_files", configs.git_files)
59+
general.setup("git_status", configs.git_status)
5960
general.setup("git_branches", configs.git_branches)
6061
general.setup("git_commits", configs.git_commits)
6162
general.setup("git_blame", configs.git_blame)

lua/fzfx/actions.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,27 @@ local function setqflist_grep(lines)
301301
})
302302
end
303303

304+
--- @param lines string[]
305+
--- @return {filename:string,lnum:integer,col:integer}[]
306+
local function _make_setqflist_git_status_items(lines)
307+
local qflist = {}
308+
for _, line in ipairs(lines) do
309+
local filename = line_helpers.parse_git_status(line)
310+
table.insert(qflist, { filename = filename, lnum = 1, col = 1 })
311+
end
312+
return qflist
313+
end
314+
315+
--- @param lines string[]
316+
local function setqflist_git_status(lines)
317+
local qflist = _make_setqflist_git_status_items(lines --[[@as table]])
318+
vim.cmd([[ :copen ]])
319+
vim.fn.setqflist({}, " ", {
320+
nr = "$",
321+
items = qflist,
322+
})
323+
end
324+
304325
--- @package
305326
--- @param lines string[]
306327
--- @return string, string
@@ -361,6 +382,29 @@ local function feed_vim_key(lines)
361382
end
362383
end
363384

385+
--- @package
386+
--- @param lines string[]
387+
--- @return string[]
388+
local function _make_edit_git_status_commands(lines)
389+
local results = {}
390+
for i, line in ipairs(lines) do
391+
local filename = line_helpers.parse_git_status(line)
392+
local edit_command = string.format("edit %s", filename)
393+
table.insert(results, edit_command)
394+
end
395+
return results
396+
end
397+
398+
-- Run 'edit' vim command on gits status results.
399+
--- @param lines string[]
400+
local function edit_git_status(lines)
401+
local edit_commands = _make_edit_git_status_commands(lines)
402+
for i, edit_command in ipairs(edit_commands) do
403+
log.debug("|fzfx.actions - edit_git_status| [%d]:[%s]", i, edit_command)
404+
vim.cmd(edit_command)
405+
end
406+
end
407+
364408
local M = {
365409
nop = nop,
366410
_make_edit_find_commands = _make_edit_find_commands,
@@ -379,16 +423,20 @@ local M = {
379423
git_checkout = git_checkout,
380424
_make_yank_git_commit_command = _make_yank_git_commit_command,
381425
yank_git_commit = yank_git_commit,
426+
_make_edit_git_status_commands = _make_edit_git_status_commands,
427+
edit_git_status = edit_git_status,
382428
_make_feed_vim_command_params = _make_feed_vim_command_params,
383429
_make_feed_vim_key_params = _make_feed_vim_key_params,
384430
feed_vim_command = feed_vim_command,
385431
feed_vim_key = feed_vim_key,
386432
_make_setqflist_find_items = _make_setqflist_find_items,
387433
_make_setqflist_rg_items = _make_setqflist_rg_items,
388434
_make_setqflist_grep_items = _make_setqflist_grep_items,
435+
_make_setqflist_git_status_items = _make_setqflist_git_status_items,
389436
setqflist_find = setqflist_find,
390437
setqflist_rg = setqflist_rg,
391438
setqflist_grep = setqflist_grep,
439+
setqflist_git_status = setqflist_git_status,
392440
}
393441

394442
return M

0 commit comments

Comments
 (0)