mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
Add mark functionality per git branch
This commit is contained in:
parent
6948a402c2
commit
60167d9b18
@ -58,12 +58,12 @@ 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[utils.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()
|
utils.mark_config_key()
|
||||||
)
|
)
|
||||||
projects[vim.loop.cwd()] = {
|
projects[utils.mark_config_key()] = {
|
||||||
mark = {
|
mark = {
|
||||||
marks = {},
|
marks = {},
|
||||||
},
|
},
|
||||||
@ -73,16 +73,19 @@ local function ensure_correct_config(config)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local proj = projects[vim.loop.cwd()]
|
local proj = projects[utils.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",
|
||||||
|
utils.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()
|
utils.mark_config_key()
|
||||||
)
|
)
|
||||||
proj.term = { cmds = {} }
|
proj.term = { cmds = {} }
|
||||||
end
|
end
|
||||||
@ -230,12 +233,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[utils.mark_config_key()].mark
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_menu_config()
|
function M.get_menu_config()
|
||||||
|
@ -4,10 +4,15 @@ local Job = require("plenary.job")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
M.project_key = vim.loop.cwd()
|
||||||
M.data_path = data_path
|
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)
|
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)
|
||||||
@ -17,24 +22,20 @@ function M.get_os_command_output(cmd, cwd)
|
|||||||
end
|
end
|
||||||
local command = table.remove(cmd, 1)
|
local command = table.remove(cmd, 1)
|
||||||
local stderr = {}
|
local stderr = {}
|
||||||
local stdout, ret = Job
|
local stdout, ret = Job:new({
|
||||||
:new({
|
command = command,
|
||||||
command = command,
|
args = cmd,
|
||||||
args = cmd,
|
cwd = cwd,
|
||||||
cwd = cwd,
|
on_stderr = function(_, data)
|
||||||
on_stderr = function(_, data)
|
table.insert(stderr, data)
|
||||||
table.insert(stderr, data)
|
end
|
||||||
end,
|
}):sync()
|
||||||
})
|
|
||||||
:sync()
|
|
||||||
return stdout, ret, stderr
|
return stdout, ret, stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.split_string(str, delimiter)
|
function M.split_string(str, delimiter)
|
||||||
local result = {}
|
local result = {}
|
||||||
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
|
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match) end
|
||||||
table.insert(result, match)
|
|
||||||
end
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user