mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Merge pull request #98 from aaronhallaert/marks_git_branch
Add mark functionality per git branch
This commit is contained in:
commit
e396483b7c
@ -46,6 +46,14 @@ local function merge_table_impl(t1, t2)
|
|||||||
end
|
end
|
||||||
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(...)
|
local function merge_tables(...)
|
||||||
log.trace("_merge_tables()")
|
log.trace("_merge_tables()")
|
||||||
local out = {}
|
local out = {}
|
||||||
@ -58,31 +66,32 @@ end
|
|||||||
local function ensure_correct_config(config)
|
local function ensure_correct_config(config)
|
||||||
log.trace("_ensure_correct_config()")
|
log.trace("_ensure_correct_config()")
|
||||||
local projects = config.projects
|
local projects = config.projects
|
||||||
if projects[vim.loop.cwd()] == nil then
|
if projects[mark_config_key()] == nil then
|
||||||
log.debug(
|
log.debug(
|
||||||
"ensure_correct_config(): No config found for:",
|
"ensure_correct_config(): No config found for:",
|
||||||
vim.loop.cwd()
|
mark_config_key()
|
||||||
)
|
)
|
||||||
projects[vim.loop.cwd()] = {
|
projects[mark_config_key()] = {
|
||||||
mark = {
|
mark = { marks = {} },
|
||||||
marks = {},
|
|
||||||
},
|
|
||||||
term = {
|
term = {
|
||||||
cmds = {},
|
cmds = {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local proj = projects[vim.loop.cwd()]
|
local proj = projects[mark_config_key()]
|
||||||
if proj.mark == nil then
|
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",
|
||||||
|
mark_config_key()
|
||||||
|
)
|
||||||
proj.mark = { marks = {} }
|
proj.mark = { marks = {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
if proj.term == nil then
|
if proj.term == nil then
|
||||||
log.debug(
|
log.debug(
|
||||||
"ensure_correct_config(): No terminal commands found for",
|
"ensure_correct_config(): No terminal commands found for",
|
||||||
vim.loop.cwd()
|
mark_config_key()
|
||||||
)
|
)
|
||||||
proj.term = { cmds = {} }
|
proj.term = { cmds = {} }
|
||||||
end
|
end
|
||||||
@ -91,9 +100,7 @@ local function ensure_correct_config(config)
|
|||||||
|
|
||||||
for idx, mark in pairs(marks) do
|
for idx, mark in pairs(marks) do
|
||||||
if type(mark) == "string" then
|
if type(mark) == "string" then
|
||||||
mark = {
|
mark = { filename = mark }
|
||||||
filename = mark,
|
|
||||||
}
|
|
||||||
marks[idx] = mark
|
marks[idx] = mark
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,7 +193,7 @@ function M.refresh_projects_b4update()
|
|||||||
cache_config
|
cache_config
|
||||||
)
|
)
|
||||||
-- save current runtime version of our project config for merging back in later
|
-- 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 = {
|
local current_p_config = {
|
||||||
projects = {
|
projects = {
|
||||||
[cwd] = ensure_correct_config(HarpoonConfig).projects[cwd],
|
[cwd] = ensure_correct_config(HarpoonConfig).projects[cwd],
|
||||||
@ -230,12 +237,12 @@ end
|
|||||||
|
|
||||||
function M.get_term_config()
|
function M.get_term_config()
|
||||||
log.trace("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
|
end
|
||||||
|
|
||||||
function M.get_mark_config()
|
function M.get_mark_config()
|
||||||
log.trace("get_mark_config()")
|
log.trace("get_mark_config()")
|
||||||
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].mark
|
return ensure_correct_config(HarpoonConfig).projects[mark_config_key()].mark
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_menu_config()
|
function M.get_menu_config()
|
||||||
|
@ -6,8 +6,20 @@ local M = {}
|
|||||||
|
|
||||||
M.data_path = data_path
|
M.data_path = data_path
|
||||||
|
|
||||||
|
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)
|
function M.normalize_path(item)
|
||||||
return Path:new(item):make_relative(vim.loop.cwd())
|
return Path:new(item):make_relative(M.project_key())
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_os_command_output(cmd, cwd)
|
function M.get_os_command_output(cmd, cwd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user