From 60167d9b185d30f73cf6eeafd92d1eb1701240d5 Mon Sep 17 00:00:00 2001 From: Aaron Hallaert Date: Sat, 4 Sep 2021 20:44:40 +0200 Subject: [PATCH] Add mark functionality per git branch --- lua/harpoon/init.lua | 19 +++++++++++-------- lua/harpoon/utils.lua | 29 +++++++++++++++-------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index cc9d80f..53f90e9 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -58,12 +58,12 @@ end local function ensure_correct_config(config) log.trace("_ensure_correct_config()") local projects = config.projects - if projects[vim.loop.cwd()] == nil then + if projects[utils.mark_config_key()] == nil then log.debug( "ensure_correct_config(): No config found for:", - vim.loop.cwd() + utils.mark_config_key() ) - projects[vim.loop.cwd()] = { + projects[utils.mark_config_key()] = { mark = { marks = {}, }, @@ -73,16 +73,19 @@ local function ensure_correct_config(config) } end - local proj = projects[vim.loop.cwd()] + local proj = projects[utils.mark_config_key()] if proj.mark == nil then - log.debug("ensure_correct_config(): No marks found for", vim.loop.cwd()) + log.debug( + "ensure_correct_config(): No marks found for", + utils.mark_config_key() + ) proj.mark = { marks = {} } end if proj.term == nil then log.debug( "ensure_correct_config(): No terminal commands found for", - vim.loop.cwd() + utils.mark_config_key() ) proj.term = { cmds = {} } end @@ -230,12 +233,12 @@ end function M.get_term_config() log.trace("get_term_config()") - return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].term + return ensure_correct_config(HarpoonConfig).projects[utils.project_key].term end function M.get_mark_config() log.trace("get_mark_config()") - return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].mark + return ensure_correct_config(HarpoonConfig).projects[utils.mark_config_key()].mark end function M.get_menu_config() diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index b2a406b..1eab2a9 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -4,10 +4,15 @@ local Job = require("plenary.job") local M = {} +M.project_key = vim.loop.cwd() M.data_path = data_path +function M.mark_config_key() + return string.gsub(vim.loop.cwd() .. '-' .. vim.fn.system('git branch --show-current'), "\n", "") +end + function M.normalize_path(item) - return Path:new(item):make_relative(vim.loop.cwd()) + return Path:new(item):make_relative(M.project_key) end function M.get_os_command_output(cmd, cwd) @@ -17,24 +22,20 @@ function M.get_os_command_output(cmd, cwd) end local command = table.remove(cmd, 1) local stderr = {} - local stdout, ret = Job - :new({ - command = command, - args = cmd, - cwd = cwd, - on_stderr = function(_, data) - table.insert(stderr, data) - end, - }) - :sync() + local stdout, ret = Job:new({ + command = command, + args = cmd, + cwd = cwd, + on_stderr = function(_, data) + table.insert(stderr, data) + end + }):sync() return stdout, ret, stderr end function M.split_string(str, delimiter) local result = {} - for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do - table.insert(result, match) - end + for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match) end return result end