mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
Merge pull request #161 from jamestrew/refactor/git-branch-specific-marks
refactor: improve git branch specific marks impl
This commit is contained in:
commit
b2bb0d6f2b
@ -19,7 +19,7 @@ feedback for harpoon (or me), make an issue!
|
|||||||
|
|
||||||
## ⇁ The Problems:
|
## ⇁ The Problems:
|
||||||
1. You're working on a codebase. medium, large, tiny, whatever. You find
|
1. You're working on a codebase. medium, large, tiny, whatever. You find
|
||||||
yourself frequenting a small set of files and you are tired of using a fuzzy finder,
|
yourself frequenting a small set of files and you are tired of using a fuzzy finder,
|
||||||
`:bnext` & `:bprev` are getting too repetitive, alternate file doesn't quite cut it, etc etc.
|
`:bnext` & `:bprev` are getting too repetitive, alternate file doesn't quite cut it, etc etc.
|
||||||
1. You want to execute some project specific commands or have any number of
|
1. You want to execute some project specific commands or have any number of
|
||||||
persistent terminals that can be easily navigated to.
|
persistent terminals that can be easily navigated to.
|
||||||
@ -133,7 +133,10 @@ global_settings = {
|
|||||||
tmux_autoclose_windows = false,
|
tmux_autoclose_windows = false,
|
||||||
|
|
||||||
-- filetypes that you want to prevent from adding to the harpoon list menu.
|
-- filetypes that you want to prevent from adding to the harpoon list menu.
|
||||||
excluded_filetypes = { "harpoon" }
|
excluded_filetypes = { "harpoon" },
|
||||||
|
|
||||||
|
-- set marks specific to each git branch inside git repository
|
||||||
|
mark_branch = false,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -46,8 +46,9 @@ local function merge_table_impl(t1, t2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mark_config_key()
|
local function mark_config_key(global_settings)
|
||||||
if HarpoonConfig.mark_branch then
|
global_settings = global_settings or M.get_global_settings()
|
||||||
|
if global_settings.mark_branch then
|
||||||
return utils.branch_key()
|
return utils.branch_key()
|
||||||
else
|
else
|
||||||
return utils.project_key()
|
return utils.project_key()
|
||||||
@ -66,12 +67,10 @@ 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[mark_config_key()] == nil then
|
local mark_key = mark_config_key(config.global_settings)
|
||||||
log.debug(
|
if projects[mark_key] == nil then
|
||||||
"ensure_correct_config(): No config found for:",
|
log.debug("ensure_correct_config(): No config found for:", mark_key)
|
||||||
mark_config_key()
|
projects[mark_key] = {
|
||||||
)
|
|
||||||
projects[mark_config_key()] = {
|
|
||||||
mark = { marks = {} },
|
mark = { marks = {} },
|
||||||
term = {
|
term = {
|
||||||
cmds = {},
|
cmds = {},
|
||||||
@ -79,19 +78,16 @@ local function ensure_correct_config(config)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local proj = projects[mark_config_key()]
|
local proj = projects[mark_key]
|
||||||
if proj.mark == nil then
|
if proj.mark == nil then
|
||||||
log.debug(
|
log.debug("ensure_correct_config(): No marks found for", mark_key)
|
||||||
"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",
|
||||||
mark_config_key()
|
mark_key
|
||||||
)
|
)
|
||||||
proj.term = { cmds = {} }
|
proj.term = { cmds = {} }
|
||||||
end
|
end
|
||||||
@ -169,6 +165,7 @@ function M.setup(config)
|
|||||||
["enter_on_sendcmd"] = false,
|
["enter_on_sendcmd"] = false,
|
||||||
["tmux_autoclose_windows"] = false,
|
["tmux_autoclose_windows"] = false,
|
||||||
["excluded_filetypes"] = { "harpoon" },
|
["excluded_filetypes"] = { "harpoon" },
|
||||||
|
["mark_branch"] = false,
|
||||||
},
|
},
|
||||||
}, expand_dir(c_config), expand_dir(u_config), expand_dir(config))
|
}, expand_dir(c_config), expand_dir(u_config), expand_dir(config))
|
||||||
|
|
||||||
|
@ -11,11 +11,20 @@ function M.project_key()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.branch_key()
|
function M.branch_key()
|
||||||
return string.gsub(
|
-- `git branch --show-current` requires Git v2.22.0+ so going with more
|
||||||
vim.loop.cwd() .. "-" .. vim.fn.system("git branch --show-current"),
|
-- widely available command
|
||||||
"\n",
|
local branch = M.get_os_command_output({
|
||||||
""
|
"git",
|
||||||
)
|
"rev-parse",
|
||||||
|
"--abbrev-ref",
|
||||||
|
"HEAD",
|
||||||
|
})[1]
|
||||||
|
|
||||||
|
if branch then
|
||||||
|
return vim.loop.cwd() .. "-" .. branch
|
||||||
|
else
|
||||||
|
return M.project_key()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.normalize_path(item)
|
function M.normalize_path(item)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user