mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-16 11:00:23 +00:00
feat(wildcards)
This commit is contained in:
parent
0eb1161288
commit
e23b7107f2
@ -7,9 +7,45 @@ local cache_config = string.format("%s/harpoon.json", data_path)
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local function get_project_config(config)
|
||||||
|
local projs = config.projects
|
||||||
|
local cwd = vim.loop.cwd()
|
||||||
|
local cwd_parts = string.gmatch(cwd, Path.sep)
|
||||||
|
|
||||||
|
for k, v in pairs(projs) do
|
||||||
|
local start = string.find(k, "{}", 1, true)
|
||||||
|
if start == nil and k == cwd then
|
||||||
|
return projs[k], k
|
||||||
|
end
|
||||||
|
|
||||||
|
local k_parts = string.gmatch(k, Path.sep)
|
||||||
|
if #k_parts == #cwd_parts then
|
||||||
|
local found = true
|
||||||
|
local wildcard = nil
|
||||||
|
for idx = 1, #k_parts do
|
||||||
|
local k_part = k_parts[idx]
|
||||||
|
found = found and (k_part == "{}" or k_part == cwd_parts[idx])
|
||||||
|
|
||||||
|
if k_part == "{}" then
|
||||||
|
wildcard = cwd_parts[idx]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if found then
|
||||||
|
return projs[k], k, wildcard
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
{
|
{
|
||||||
projects = {
|
projects = {
|
||||||
|
["/path/to/other/{}"] = {
|
||||||
|
// TODO: pattern matching
|
||||||
|
}
|
||||||
["/path/to/director"] = {
|
["/path/to/director"] = {
|
||||||
term = {
|
term = {
|
||||||
cmds = {
|
cmds = {
|
||||||
@ -23,6 +59,10 @@ local M = {}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
menu = {
|
||||||
|
// TODO: Be filled in on settings...
|
||||||
|
// WE should also consider just having a help doc
|
||||||
|
}
|
||||||
... high level settings
|
... high level settings
|
||||||
}
|
}
|
||||||
--]]
|
--]]
|
||||||
@ -52,9 +92,11 @@ local function merge_tables(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function ensure_correct_config(config)
|
local function ensure_correct_config(config)
|
||||||
local projects = config.projects
|
local projects, cwd, wildcard = get_project_config(config)
|
||||||
if projects[vim.loop.cwd()] == nil then
|
|
||||||
projects[vim.loop.cwd()] = {
|
cwd = cwd or vim.loop.cwd
|
||||||
|
if projects[cwd] == nil then
|
||||||
|
projects[cwd] = {
|
||||||
mark = {
|
mark = {
|
||||||
marks = {}
|
marks = {}
|
||||||
},
|
},
|
||||||
@ -64,7 +106,8 @@ local function ensure_correct_config(config)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local proj = projects[vim.loop.cwd()]
|
local proj = projects[cwd]
|
||||||
|
proj.wildcard = wildcard
|
||||||
if proj.mark == nil then
|
if proj.mark == nil then
|
||||||
proj.mark = {marks = {}}
|
proj.mark = {marks = {}}
|
||||||
end
|
end
|
||||||
@ -146,6 +189,10 @@ M.get_term_config = function()
|
|||||||
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].term
|
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].term
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.get_wildcard = function()
|
||||||
|
return ensure_correct_config(HarpoonConfig).projects.wildcard
|
||||||
|
end
|
||||||
|
|
||||||
M.get_mark_config = function()
|
M.get_mark_config = function()
|
||||||
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].mark
|
return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].mark
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
local harpoon = require('harpoon')
|
local harpoon = require('harpoon')
|
||||||
local Path = require("plenary.path")
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
local terminals = {}
|
local terminals = {}
|
||||||
@ -25,11 +24,25 @@ local function create_terminal()
|
|||||||
return buf_id, term_id
|
return buf_id, term_id
|
||||||
end
|
end
|
||||||
|
|
||||||
function getCmd(idx)
|
local function process_wildcards(cmd)
|
||||||
return
|
local wc = harpoon.get_wildcard()
|
||||||
|
if wc == nil then
|
||||||
|
return cmd
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd_parts = string.gmatch(cmd, "{}")
|
||||||
|
if #cmd_parts == 1 then
|
||||||
|
return cmd
|
||||||
|
end
|
||||||
|
|
||||||
|
local new_cmd = cmd[1]
|
||||||
|
for idx = 2, #cmd_parts do
|
||||||
|
new_cmd = new_cmd .. wc .. cmd_parts[idx]
|
||||||
|
end
|
||||||
|
return new_cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
function find_terminal(idx)
|
local function find_terminal(idx)
|
||||||
local term_handle = terminals[idx]
|
local term_handle = terminals[idx]
|
||||||
if not term_handle or not vim.api.nvim_buf_is_valid(term_handle.buf_id) then
|
if not term_handle or not vim.api.nvim_buf_is_valid(term_handle.buf_id) then
|
||||||
local buf_id, term_id = create_terminal()
|
local buf_id, term_id = create_terminal()
|
||||||
@ -59,6 +72,8 @@ M.sendCommand = function(idx, cmd)
|
|||||||
cmd = harpoon.get_term_config().cmds[cmd]
|
cmd = harpoon.get_term_config().cmds[cmd]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cmd = process_wildcards(cmd)
|
||||||
|
|
||||||
if cmd then
|
if cmd then
|
||||||
vim.fn.chansend(term_handle.term_id, cmd)
|
vim.fn.chansend(term_handle.term_id, cmd)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user