diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index 53f90e9..b1d7d02 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -46,6 +46,14 @@ local function merge_table_impl(t1, t2) end end +local function mark_config_key() + if HarpoonConfig.mark_branch then + return utils.branch_key() + else + return utils.project_key + end +end + local function merge_tables(...) log.trace("_merge_tables()") local out = {} @@ -58,12 +66,12 @@ end local function ensure_correct_config(config) log.trace("_ensure_correct_config()") local projects = config.projects - if projects[utils.mark_config_key()] == nil then + if projects[mark_config_key()] == nil then log.debug( "ensure_correct_config(): No config found for:", - utils.mark_config_key() + mark_config_key() ) - projects[utils.mark_config_key()] = { + projects[mark_config_key()] = { mark = { marks = {}, }, @@ -73,11 +81,11 @@ local function ensure_correct_config(config) } end - local proj = projects[utils.mark_config_key()] + local proj = projects[mark_config_key()] if proj.mark == nil then log.debug( "ensure_correct_config(): No marks found for", - utils.mark_config_key() + mark_config_key() ) proj.mark = { marks = {} } end @@ -85,7 +93,7 @@ local function ensure_correct_config(config) if proj.term == nil then log.debug( "ensure_correct_config(): No terminal commands found for", - utils.mark_config_key() + mark_config_key() ) proj.term = { cmds = {} } end @@ -238,7 +246,7 @@ end function M.get_mark_config() log.trace("get_mark_config()") - return ensure_correct_config(HarpoonConfig).projects[utils.mark_config_key()].mark + return ensure_correct_config(HarpoonConfig).projects[mark_config_key()].mark end function M.get_menu_config() diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index 1eab2a9..cd897d8 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -4,7 +4,9 @@ local Job = require("plenary.job") local M = {} -M.project_key = vim.loop.cwd() +local project_key = vim.loop.cwd() +M.project_key = project_key +M.branch_key = vim.loop.cwd() M.data_path = data_path function M.mark_config_key() @@ -12,7 +14,7 @@ function M.mark_config_key() end function M.normalize_path(item) - return Path:new(item):make_relative(M.project_key) + return Path:new(item):make_relative(M.branch_key) end function M.get_os_command_output(cmd, cwd)