|
12 | 12 |
|
13 | 13 | -- Map a key to both insert and normal modes
|
14 | 14 | local function omnimap(map_func, key, handler)
|
15 |
| - map_func('i', key, handler) |
16 |
| - map_func('n', key, handler) |
| 15 | + map_func("i", key, handler) |
| 16 | + map_func("n", key, handler) |
17 | 17 | end
|
18 | 18 |
|
19 | 19 | --- Opens a Telescope window with a list of local branches
|
@@ -117,7 +117,63 @@ M.search_log_content = function()
|
117 | 117 | .new({
|
118 | 118 | results_title = "Commits",
|
119 | 119 | prompt_title = "Git log content (added, removed or updated text)",
|
120 |
| - finder = gu.git_log_grepper_on_content(), |
| 120 | + finder = gu.git_log_grepper_on_content({}), |
| 121 | + -- finder = finders.new_oneshot_job({'git', 'log', location}), |
| 122 | + previewer = previewers.new_termopen_previewer({ |
| 123 | + get_command = function(entry) |
| 124 | + local commit_hash = entry.opts.commit_hash |
| 125 | + local prompt = entry.opts.prompt |
| 126 | + local command = { |
| 127 | + "git", |
| 128 | + "diff", |
| 129 | + string.format("%s~", commit_hash), |
| 130 | + commit_hash, |
| 131 | + } |
| 132 | + |
| 133 | + if prompt and prompt ~= "" then |
| 134 | + table.insert(command, "-G") |
| 135 | + table.insert(command, prompt) |
| 136 | + end |
| 137 | + |
| 138 | + return command |
| 139 | + end, |
| 140 | + }), |
| 141 | + -- sorter = sorters.highlighter_only(), |
| 142 | + attach_mappings = function(_, map) |
| 143 | + omnimap(map, "<CR>", function(prompt_bufnr) |
| 144 | + actions.close(prompt_bufnr) |
| 145 | + local selection = action_state.get_selected_entry() |
| 146 | + local commit_hash = selection.opts.commit_hash |
| 147 | + |
| 148 | + gu.open_diff_view(commit_hash) |
| 149 | + end) |
| 150 | + omnimap(map, "<C-o>", function(prompt_bufnr) |
| 151 | + actions.close(prompt_bufnr) |
| 152 | + local selection = action_state.get_selected_entry() |
| 153 | + |
| 154 | + vim.api.nvim_command(":GBrowse " .. selection.opts.commit_hash) |
| 155 | + end) |
| 156 | + |
| 157 | + return true |
| 158 | + end, |
| 159 | + }) |
| 160 | + :find() |
| 161 | +end |
| 162 | + |
| 163 | +--- Same as `search_log_content` but with respect to the current file |
| 164 | +--- |
| 165 | +--- <CR> opens a diff for the current file with the selected commit |
| 166 | +--- <C-o> opens a the selected commit in the browser |
| 167 | +M.search_log_content_file = function() |
| 168 | + -- local file_name = vim.fn.expand("%") |
| 169 | + -- local relative_file_name = vim.fn.expand("%:~:.") |
| 170 | + |
| 171 | + -- git log -L741,751:'app/models/patients/patient.rb' --format='%C(auto)%h \t %as \t %C(green)%an _ %Creset %s' |
| 172 | + pickers |
| 173 | + .new({ |
| 174 | + results_title = "Commits", |
| 175 | + prompt_title = "Git log content (added, removed or updated text in this file)", |
| 176 | + finder = gu.git_log_grepper_on_content({ bufnr = vim.fn.bufnr() }), |
121 | 177 | -- finder = finders.new_oneshot_job({'git', 'log', location}),
|
122 | 178 | previewer = previewers.new_termopen_previewer({
|
123 | 179 | get_command = function(entry)
|
|
0 commit comments