mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat(polar): mutex is about to bork me
This commit is contained in:
parent
7a9ef73961
commit
4e16fc9026
@ -1,3 +1,7 @@
|
|||||||
|
# WARNING
|
||||||
|
This is still beta. We are getting there, but its not as fast as I would like.
|
||||||
|
Therefore APIs are subject to change.
|
||||||
|
|
||||||
# harpoon
|
# harpoon
|
||||||
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
||||||
|
|
||||||
|
@ -1,28 +1,47 @@
|
|||||||
local terminals = require("harpoon.terminal")
|
local terminals = require("harpoon.term")
|
||||||
local manage = require("harpoon.manage-a-mark")
|
local manage = require("harpoon.mark")
|
||||||
local cwd = cwd or vim.loop.cwd()
|
local cwd = cwd or vim.loop.cwd()
|
||||||
local config_path = vim.fn.stdpath("config")
|
local config_path = vim.fn.stdpath("config")
|
||||||
local terminal_config = string.format("%s/harpoon-terminal.json", config_path)
|
local data_path = vim.fn.stdpath("data")
|
||||||
|
local user_terminal_config = string.format("%s/harpoon-terminal.json", config_path)
|
||||||
|
local cache_terminal_config = string.format("%s/harpoon-terminal.json", data_path)
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
function expand_dir(projects)
|
||||||
|
local expanded_config = {}
|
||||||
|
for k in pairs(projects) do
|
||||||
|
local expanded_path = Path.new(k):expand()
|
||||||
|
projects[expanded_path] = projects[k]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 1. saved. Where do we save?
|
||||||
M.setup = function(config)
|
M.setup = function(config)
|
||||||
function read_terminal_config()
|
function read_terminal_config(config)
|
||||||
return vim.fn.json_decode(Path:new(terminal_config):read())
|
return vim.fn.json_decode(Path:new(config):read())
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: Merge the configs instead of falling back
|
|
||||||
if not config then
|
if not config then
|
||||||
local ok, res = pcall(read_terminal_config)
|
config = {}
|
||||||
if ok then
|
|
||||||
config = res
|
|
||||||
else
|
|
||||||
config = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
terminals.setup(config)
|
local ok, user_config = pcall(read_terminal_config, user_terminal_config)
|
||||||
manage.setup(config)
|
local ok2, cache_config = pcall(read_terminal_config, data_terminal_config)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
user_config = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if not ok2 then
|
||||||
|
cache_config = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local complete_config =
|
||||||
|
vim.tbl_deep_extend("force", {}, cache_config, user_config, config)
|
||||||
|
|
||||||
|
terminals.setup(complete_config)
|
||||||
|
manage.setup(complete_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -2,16 +2,34 @@ local Path = require('plenary.path')
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
harpoon_win_id = nil
|
|
||||||
harpoon_bufh = nil
|
|
||||||
|
|
||||||
local cwd = cwd or vim.loop.cwd()
|
local cwd = cwd or vim.loop.cwd()
|
||||||
local data_path = vim.fn.stdpath("data")
|
local data_path = vim.fn.stdpath("data")
|
||||||
|
local mark_config = {}
|
||||||
|
|
||||||
cwd = cwd:gsub("/", "_")
|
cwd = cwd:gsub("/", "_")
|
||||||
|
|
||||||
local file_name = string.format("%s/%s.cache", data_path, cwd)
|
local file_name = string.format("%s/%s.cache", data_path, cwd)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
{
|
||||||
|
projects = {
|
||||||
|
["/path/to/director"] = {
|
||||||
|
term = {
|
||||||
|
cmds = {
|
||||||
|
}
|
||||||
|
... is there antyhnig that could be options?
|
||||||
|
},
|
||||||
|
mark = {
|
||||||
|
marks = {
|
||||||
|
}
|
||||||
|
... is there antyhnig that could be options?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
... high level settings
|
||||||
|
}
|
||||||
|
--]]
|
||||||
|
|
||||||
function get_id_or_current_buffer(id)
|
function get_id_or_current_buffer(id)
|
||||||
if id == nil then
|
if id == nil then
|
||||||
return vim.fn.bufname(vim.fn.bufnr())
|
return vim.fn.bufname(vim.fn.bufnr())
|
||||||
@ -36,6 +54,18 @@ function hydrate_from_cache()
|
|||||||
return {}, {}
|
return {}, {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.setup = function(config)
|
||||||
|
if not config.projects[cwd] then
|
||||||
|
mark_config = {}
|
||||||
|
else
|
||||||
|
mark_config = config.projects[cwd].mark
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.get_config = function()
|
||||||
|
return mark_config
|
||||||
|
end
|
||||||
|
|
||||||
M.save = function()
|
M.save = function()
|
||||||
Path:new(file_name):write(vim.fn.json_encode(marked_files), 'w')
|
Path:new(file_name):write(vim.fn.json_encode(marked_files), 'w')
|
||||||
end
|
end
|
||||||
@ -201,8 +231,5 @@ M.get_length = function()
|
|||||||
return #marked_files
|
return #marked_files
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setup = function()
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
@ -3,9 +3,8 @@ local cwd = cwd or vim.loop.cwd()
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
harpoon_terminal_config = { }
|
local terminal_config = { }
|
||||||
harpoon_terminals = {}
|
local terminals = {}
|
||||||
harpoon_init = false
|
|
||||||
|
|
||||||
function create_terminal()
|
function create_terminal()
|
||||||
local current_id = vim.fn.bufnr()
|
local current_id = vim.fn.bufnr()
|
||||||
@ -38,26 +37,39 @@ lua require("harpoon").setup({
|
|||||||
--]]
|
--]]
|
||||||
|
|
||||||
function getCmd(idx)
|
function getCmd(idx)
|
||||||
local commandSet = harpoon_terminal_config[cwd]
|
local commandSet = terminal_config[cwd]
|
||||||
if not commandSet then
|
if not commandSet then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return commandSet[idx]
|
return commandSet[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setup = function(config)
|
--[[
|
||||||
|
{
|
||||||
local expanded_config = {}
|
projects: {
|
||||||
for k in pairs(config.terminal) do
|
"/path/to/dir": {
|
||||||
local expanded_path = Path.new(k):expand()
|
term: {
|
||||||
expanded_config[expanded_path] = config.terminal[k]
|
cmds: string[],
|
||||||
|
... top level settings .. (we don't have)
|
||||||
|
}
|
||||||
|
mark: {
|
||||||
|
marks: string[], // very skept -- has odd behavior
|
||||||
|
... top level settings .. (we don't have)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
--]]
|
||||||
|
M.setup = function(config)
|
||||||
|
if not config.projects[cwd] then
|
||||||
|
terminal_config = {}
|
||||||
|
else
|
||||||
|
terminal_config = config.projects[cwd].term
|
||||||
end
|
end
|
||||||
|
|
||||||
harpoon_terminal_config = expanded_config or {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.gotoTerminal = function(idx)
|
M.gotoTerminal = function(idx)
|
||||||
local term_handle = harpoon_terminals[idx]
|
local term_handle = terminals[idx]
|
||||||
|
|
||||||
if not term_handle then
|
if not term_handle then
|
||||||
local buf_id, term_id = create_terminal()
|
local buf_id, term_id = create_terminal()
|
||||||
@ -68,18 +80,18 @@ M.gotoTerminal = function(idx)
|
|||||||
buf_id = buf_id,
|
buf_id = buf_id,
|
||||||
term_id = term_id
|
term_id = term_id
|
||||||
}
|
}
|
||||||
harpoon_terminals[idx] = term_handle
|
terminals[idx] = term_handle
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_current_buf(term_handle.buf_id)
|
vim.api.nvim_set_current_buf(term_handle.buf_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.sendCommand = function(idx, cmd)
|
M.sendCommand = function(idx, cmd)
|
||||||
local term_handle = harpoon_terminals[idx]
|
local term_handle = terminals[idx]
|
||||||
|
|
||||||
if not term_handle then
|
if not term_handle then
|
||||||
M.gotoTerminal(idx)
|
M.gotoTerminal(idx)
|
||||||
term_handle = harpoon_terminals[idx]
|
term_handle = terminals[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(cmd) == "number" then
|
if type(cmd) == "number" then
|
@ -1,5 +1,5 @@
|
|||||||
-- TODO: Harpooned
|
-- TODO: Harpooned
|
||||||
local Marker = require('harpoon.manage-a-mark')
|
local Marker = require('harpoon.mark')
|
||||||
local eq = assert.are.same
|
local eq = assert.are.same
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local Path = require('plenary.path')
|
local Path = require('plenary.path')
|
||||||
local float = require('plenary.window.float')
|
local float = require('plenary.window.float')
|
||||||
local Marked = require('harpoon.manage-a-mark')
|
local Marked = require('harpoon.mark')
|
||||||
|
|
||||||
local factorw = 0.42069
|
local factorw = 0.42069
|
||||||
local factorh = 0.69420
|
local factorh = 0.69420
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
augroup THE_PRIMEAGEN_HARPOON
|
augroup THE_PRIMEAGEN_HARPOON
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd VimLeave * :lua require('harpoon.manage-a-mark').save()
|
autocmd VimLeave * :lua require('harpoon.mark').save()
|
||||||
autocmd BufLeave * :lua require('harpoon.manage-a-mark').store_offset()
|
autocmd BufLeave * :lua require('harpoon.mark').store_offset()
|
||||||
augroup END
|
augroup END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user