Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ Enable `show_builtin_git_pickers` to additionally show builtin git pickers.
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
entry_default_author_or_date = "author", -- one of "author" or "date"
keymaps = {
-- following keymaps can be overridden
toggle_date_author = "<C-w>",
open_commit_in_browser = "<C-o>",
copy_commit_hash = "<C-y>",
}

-- Telescope layout setup
telescope_theme = {
Expand Down
11 changes: 8 additions & 3 deletions lua/advanced_git_search/telescope/mappings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local global_actions = require("advanced_git_search.actions")

local file_utils = require("advanced_git_search.utils.file")
local git_utils = require("advanced_git_search.utils.git")
local config = require("advanced_git_search.utils.config")

-- Map a key to both insert and normal modes
local function omnimap(map_func, key, handler)
Expand All @@ -24,7 +25,7 @@ local toggle_date_author = function(prompt_bufnr)
end

M.toggle_entry_value = function(map)
omnimap(map, "<C-w>", toggle_date_author)
omnimap(map, config.get_keymap("toggle_date_author"), toggle_date_author)
end

-------------------------------------------------------------------------------
Expand All @@ -38,7 +39,11 @@ end

--- Open browser at commmit (from entry) with <C-o>
M.open_selected_commit_in_browser = function(map)
omnimap(map, "<C-o>", open_commit_in_browser)
omnimap(
map,
config.get_keymap("open_commit_in_browser"),
open_commit_in_browser
)
end

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -97,7 +102,7 @@ end

--- copy commit hash to clipboard with <C-y>
M.copy_commit_hash_to_clipboard = function(map)
omnimap(map, "<C-y>", copy_commit_hash)
omnimap(map, config.get_keymap("copy_commit_hash"), copy_commit_hash)
end

-------------------------------------------------------------------------------
Expand Down
42 changes: 42 additions & 0 deletions lua/advanced_git_search/utils/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,48 @@ M.git_diff_flags = function()
return git_diff_flags
end

local function get_keymaps()
local keymaps = {
toggle_date_author = "<C-w>",
open_commit_in_browser = "<C-o>",
copy_commit_hash = "<C-y>",
}
keymaps = vim.tbl_extend("force", keymaps, config["keymaps"] or {})

if type(keymaps) ~= "table" then
vim.notify(
"keymaps config must be a table",
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return nil
end

return keymaps
end

M.get_keymap = function(entry)
if get_keymaps()[entry] == nil then
vim.notify(
"No keymap defined for " .. entry,
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return ""
end

if type(get_keymaps()[entry]) ~= "string" then
vim.notify(
"Keymap for " .. entry .. " must be a string",
vim.log.levels.ERROR,
{ title = "Advanced Git Search" }
)
return ""
end

return get_keymaps()[entry]
end

M.entry_default_author_or_date = function()
return config["entry_default_author_or_date"] or "author"
end
Expand Down