Skip to content

Commit de813bc

Browse files
Add subcommands for "AdvancedGitSearch" (#50)
* Add subcommands to AdvancedGitSearch Signed-off-by: Aaron Hallaert <[email protected]> * Update readme for subcommands Signed-off-by: Aaron Hallaert <[email protected]> --------- Signed-off-by: Aaron Hallaert <[email protected]>
1 parent 258c4fd commit de813bc

File tree

4 files changed

+44
-86
lines changed

4 files changed

+44
-86
lines changed

README.md

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,24 @@ An advanced git search extension for `Telescope` and `fzf-lua`.
44

55
Search your git history by commit message, content and author in Neovim
66

7-
## 🖥️ Usage
7+
## 🚀 Usage
88

9-
- [Demo](https://www.youtube.com/watch?v=bO0uYLlHtYo)
9+
[Demo](https://www.youtube.com/watch?v=bO0uYLlHtYo)
1010

11-
### 📖 Open a picker
11+
- __📖 Open a picker__
1212

13-
#### 🔭 Telescope
13+
`:AdvancedGitSearch` or `:AdvancedGitSearch {command}`
1414

15-
```vim
16-
:Telescope advanced_git_search {function_name}
17-
```
18-
19-
> or in lua
20-
21-
```lua
22-
require('telescope').extensions.advanced_git_search.{function_name}()
23-
```
24-
25-
> or through another Telescope picker
26-
27-
execute `:AdvancedGitSearch`, choose your picker and press `<CR>`
28-
29-
#### 🧎 fzf-lua
30-
31-
```lua
32-
require('advanced_git_search.fzf').{function_name}()
33-
```
34-
35-
> or through another picker
36-
37-
execute `:AdvancedGitSearch`, choose your picker and press `<CR>`
15+
- __🔎 Enter a query__
3816

39-
### 🔎 Enter a query
17+
Your usual search experience. See the individual commands for the grep behaviour.
4018

41-
Your usual search experience. See the individual commands for the grep behaviour.
19+
- __✏️ Further search on commit author with `@`__
4220

43-
### ✏️ Further search on commit author with `@`
44-
45-
The prompt is split on `@`. Everything following the `@` is the pattern for
21+
The prompt is split on `@`. Everything following the `@` is the pattern for
4622
the author name.
4723

48-
## ️Commands
24+
## ️ Commands
4925

5026
### 1. search_log_content -- Search in repo log content
5127

@@ -95,34 +71,7 @@ selected lines
9571

9672
_Grep behaviour_: filter on commit message.
9773

98-
#### How to use
99-
100-
> _This workaround only applies when you use the following command. (Telescope)_
101-
>
102-
> ```vim
103-
> :Telescope advanced_git_search diff_commit_line
104-
> ```
105-
106-
First you have to select the lines in visual mode, then go back to normal
107-
mode and execute this command.
108-
To make a bit easier, you can wrap it in a user command and define a keybind:
109-
110-
```lua
111-
vim.api.nvim_create_user_command(
112-
"DiffCommitLine",
113-
"lua require('telescope').extensions.advanced_git_search.diff_commit_line()",
114-
{ range = true }
115-
)
116-
117-
vim.api.nvim_set_keymap(
118-
"v",
119-
"<leader>dcl",
120-
":DiffCommitLine<CR>",
121-
{ noremap = true }
122-
)
123-
```
124-
125-
> No extra setup is needed when you use `:AdvancedGitSearch`.
74+
> Use `:'<,'>AdvancedGitSearch diff_commit_line` (with a visual range).
12675
12776
#### _Keymaps_
12877

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
local M = {}
22
local config = require("advanced_git_search.utils.config")
3+
local setup = require("advanced_git_search.utils.setup")
34

45
M.setup = function(opts)
56
config.setup(opts)
67

7-
vim.api.nvim_create_user_command(
8-
"AdvancedGitSearch",
9-
"lua require('advanced_git_search.fzf').show_custom_functions()",
10-
{ range = true }
11-
)
8+
local pickers = require("advanced_git_search.fzf.pickers")
9+
setup.setup_user_command(pickers)
1210
end
1311

14-
M.search_log_content =
15-
require("advanced_git_search.fzf.pickers").search_log_content
16-
17-
M.search_log_content_file =
18-
require("advanced_git_search.fzf.pickers").search_log_content_file
19-
20-
M.diff_commit_line = require("advanced_git_search.fzf.pickers").diff_commit_line
21-
22-
M.diff_commit_file = require("advanced_git_search.fzf.pickers").diff_commit_file
23-
24-
M.diff_branch_file = require("advanced_git_search.fzf.pickers").diff_branch_file
25-
26-
M.show_custom_functions =
27-
require("advanced_git_search.fzf.pickers").show_custom_functions
28-
2912
return M
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
local M = {}
2+
3+
M.setup_user_command = function(pickers)
4+
vim.api.nvim_create_user_command("AdvancedGitSearch", function(opt)
5+
local f = opt.fargs[1]
6+
7+
if f == nil then
8+
pickers.show_custom_functions()
9+
else
10+
pickers[f]()
11+
end
12+
end, {
13+
range = true,
14+
nargs = "?",
15+
complete = function(_)
16+
local completion_list = {}
17+
local n = 0
18+
for k, _ in pairs(pickers) do
19+
if k ~= "show_custom_functions" then
20+
n = n + 1
21+
completion_list[n] = k
22+
end
23+
end
24+
return completion_list
25+
end,
26+
})
27+
end
28+
29+
return M
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
local pickers = require("advanced_git_search.telescope.pickers")
22
local config = require("advanced_git_search.utils.config")
3+
local setup = require("advanced_git_search.utils.setup")
34

45
return require("telescope").register_extension({
56
setup = function(ext_config, _)
67
config.setup(ext_config)
78

8-
vim.api.nvim_create_user_command(
9-
"AdvancedGitSearch",
10-
"lua require('telescope').extensions.advanced_git_search.show_custom_functions()",
11-
{ range = true }
12-
)
9+
setup.setup_user_command(pickers)
1310
end,
1411
exports = pickers,
1512
})

0 commit comments

Comments
 (0)