Skip to content

Commit 9d5f3fd

Browse files
committed
Add mappings for copy_commit hash
1 parent 066219c commit 9d5f3fd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lua/advanced_git_search/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ M.diff_commit_line = function()
7474
attach_mappings = function(_, map)
7575
ags_mappings.open_diff_view_current_file_selected_commit(map)
7676
ags_mappings.open_selected_commit_in_browser(map)
77+
ags_mappings.copy_commit_hash_to_clipboard(map)
7778
return true
7879
end,
7980
})
@@ -98,6 +99,7 @@ M.search_log_content = function()
9899
attach_mappings = function(_, map)
99100
ags_mappings.open_diff_view_current_file_selected_commit(map)
100101
ags_mappings.open_selected_commit_in_browser(map)
102+
ags_mappings.copy_commit_hash_to_clipboard(map)
101103
return true
102104
end,
103105
})
@@ -126,6 +128,7 @@ M.search_log_content_file = function()
126128
attach_mappings = function(_, map)
127129
ags_mappings.open_diff_view_current_file_selected_commit(map)
128130
ags_mappings.open_selected_commit_in_browser(map)
131+
ags_mappings.copy_commit_hash_to_clipboard(map)
129132

130133
return true
131134
end,
@@ -151,6 +154,7 @@ M.diff_commit_file = function()
151154
ags_mappings.open_diff_view_current_file_selected_commit(map)
152155
ags_mappings.show_entire_commit(map)
153156
ags_mappings.open_selected_commit_in_browser(map)
157+
ags_mappings.copy_commit_hash_to_clipboard(map)
154158

155159
return true
156160
end,

lua/advanced_git_search/mappings/init.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ M.show_entire_commit = function(map)
8787
omnimap(map, "<C-e>", open_entire_commit)
8888
end
8989

90+
-------------------------------------------------------------------------------
91+
local copy_commit_hash = function(_)
92+
local selection = action_state.get_selected_entry()
93+
local commit_hash = selection.opts.commit_hash
94+
vim.notify(
95+
"Copied commit hash " .. commit_hash .. " to clipboard",
96+
vim.log.levels.INFO,
97+
{ title = "Advanced Git Search" }
98+
)
99+
100+
vim.fn.setreg("+", commit_hash)
101+
vim.fn.setreg("*", commit_hash)
102+
end
103+
104+
--- copy commit hash to clipboard with <C-y>
105+
M.copy_commit_hash_to_clipboard = function(map)
106+
omnimap(map, "<C-y>", copy_commit_hash)
107+
end
108+
90109
-------------------------------------------------------------------------------
91110
local checkout = function(prompt_bufnr)
92111
actions.close(prompt_bufnr)

0 commit comments

Comments
 (0)