diff --git a/README.md b/README.md index 7a55202..d6a7741 100644 --- a/README.md +++ b/README.md @@ -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 = "", + open_commit_in_browser = "", + copy_commit_hash = "", + } -- Telescope layout setup telescope_theme = { diff --git a/lua/advanced_git_search/telescope/mappings/init.lua b/lua/advanced_git_search/telescope/mappings/init.lua index dc9e1ff..ee7cd2f 100644 --- a/lua/advanced_git_search/telescope/mappings/init.lua +++ b/lua/advanced_git_search/telescope/mappings/init.lua @@ -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) @@ -24,7 +25,7 @@ local toggle_date_author = function(prompt_bufnr) end M.toggle_entry_value = function(map) - omnimap(map, "", toggle_date_author) + omnimap(map, config.get_keymap("toggle_date_author"), toggle_date_author) end ------------------------------------------------------------------------------- @@ -38,7 +39,11 @@ end --- Open browser at commmit (from entry) with M.open_selected_commit_in_browser = function(map) - omnimap(map, "", open_commit_in_browser) + omnimap( + map, + config.get_keymap("open_commit_in_browser"), + open_commit_in_browser + ) end ------------------------------------------------------------------------------- @@ -97,7 +102,7 @@ end --- copy commit hash to clipboard with M.copy_commit_hash_to_clipboard = function(map) - omnimap(map, "", copy_commit_hash) + omnimap(map, config.get_keymap("copy_commit_hash"), copy_commit_hash) end ------------------------------------------------------------------------------- diff --git a/lua/advanced_git_search/utils/config.lua b/lua/advanced_git_search/utils/config.lua index 4d8bd83..76ce23b 100644 --- a/lua/advanced_git_search/utils/config.lua +++ b/lua/advanced_git_search/utils/config.lua @@ -32,6 +32,48 @@ M.git_diff_flags = function() return git_diff_flags end +local function get_keymaps() + local keymaps = { + toggle_date_author = "", + open_commit_in_browser = "", + copy_commit_hash = "", + } + 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