Add mark functionality per git branch

This commit is contained in:
Aaron Hallaert 2021-09-04 20:44:40 +02:00
parent 6948a402c2
commit 60167d9b18
2 changed files with 26 additions and 22 deletions

View File

@ -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()

View File

@ -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