Change project_key to function

This commit is contained in:
Aaron Hallaert 2021-11-10 09:32:47 +01:00
parent 968b93cf76
commit accf7ef4ef
2 changed files with 29 additions and 24 deletions

View File

@ -50,7 +50,7 @@ local function mark_config_key()
if HarpoonConfig.mark_branch then
return utils.branch_key()
else
return utils.project_key
return utils.project_key()
end
end
@ -72,9 +72,7 @@ local function ensure_correct_config(config)
mark_config_key()
)
projects[mark_config_key()] = {
mark = {
marks = {},
},
mark = { marks = {} },
term = {
cmds = {},
},
@ -102,9 +100,7 @@ local function ensure_correct_config(config)
for idx, mark in pairs(marks) do
if type(mark) == "string" then
mark = {
filename = mark,
}
mark = { filename = mark }
marks[idx] = mark
end
@ -197,7 +193,7 @@ function M.refresh_projects_b4update()
cache_config
)
-- save current runtime version of our project config for merging back in later
local cwd = vim.loop.cwd()
local cwd = mark_config_key()
local current_p_config = {
projects = {
[cwd] = ensure_correct_config(HarpoonConfig).projects[cwd],
@ -241,7 +237,7 @@ end
function M.get_term_config()
log.trace("get_term_config()")
return ensure_correct_config(HarpoonConfig).projects[utils.project_key].term
return ensure_correct_config(HarpoonConfig).projects[utils.project_key()].term
end
function M.get_mark_config()

View File

@ -4,17 +4,22 @@ local Job = require("plenary.job")
local M = {}
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()
return string.gsub(vim.loop.cwd() .. '-' .. vim.fn.system('git branch --show-current'), "\n", "")
function M.project_key()
return vim.loop.cwd()
end
function M.branch_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(M.branch_key)
return Path:new(item):make_relative(M.project_key())
end
function M.get_os_command_output(cmd, cwd)
@ -24,20 +29,24 @@ 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