mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat(setup): and having git controllable configs
This commit is contained in:
parent
ec5f027680
commit
eaf39b775d
15
README.md
15
README.md
@ -1,8 +1,15 @@
|
|||||||
# harpoon
|
# harpoon
|
||||||
Harpoon is a terminal navigator for Neovim (currently, but I want vim to work
|
The goal of Harpoon is to get you where you want with the fewest keystrokes.
|
||||||
as well). Harpoon itself does not provide much for functionality other than
|
|
||||||
goto a terminal, set a terminal, and sending commands. Where it shines is in
|
## The Problem
|
||||||
local configs.
|
You work on code. The code base is medium, large, tiny, whatever. You find
|
||||||
|
yourself frequenting a small set of files (maybe it depends on task) and you
|
||||||
|
are tired of using a fuzzy finder, :bnext/prev, alternate file doesn't quite
|
||||||
|
cut it, etc etc.
|
||||||
|
|
||||||
|
## The Solution
|
||||||
|
The ability to specify, or on the fly, mark and create persisting key strokes
|
||||||
|
to go to the files you want. This includes terminal navigation.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Simply install via your favorite plugin manager.
|
Simply install via your favorite plugin manager.
|
||||||
|
1
TODO.md
1
TODO.md
@ -1,6 +1,7 @@
|
|||||||
### Manage A Mark 1.0
|
### Manage A Mark 1.0
|
||||||
* Logo
|
* Logo
|
||||||
* linexcol offset in saved file
|
* linexcol offset in saved file
|
||||||
|
* (bug) When new files are added, they do start off as absolute paths (their expand("%"))
|
||||||
|
|
||||||
### Harpoon (upon requests)
|
### Harpoon (upon requests)
|
||||||
* Add hooks for vim so that someone can make it for me
|
* Add hooks for vim so that someone can make it for me
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
fun harpoon#nav(id)
|
|
||||||
call luaeval("require('harpoon.ui').nav(_A[1])", [a:id])
|
|
||||||
endfun
|
|
||||||
|
|
||||||
fun harpoon#cmd(cmd)
|
|
||||||
" TODO: I am sure I'll use this
|
|
||||||
endfun
|
|
29
lua/harpoon/init.lua
Normal file
29
lua/harpoon/init.lua
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
local terminals = require("harpoon.terminal")
|
||||||
|
local manage = require("harpoon.manage-a-mark")
|
||||||
|
local cwd = cwd or vim.loop.cwd()
|
||||||
|
local config_path = vim.fn.stdpath("config")
|
||||||
|
local terminal_config = string.format("%s/harpoon-terminal.json", config_path)
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.setup = function(config)
|
||||||
|
function read_terminal_config()
|
||||||
|
return vim.fn.json_decode(Path:new(terminal_config):read())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: Merge the configs instead of falling back
|
||||||
|
if not config then
|
||||||
|
local ok, res = pcall(read_terminal_config)
|
||||||
|
if ok then
|
||||||
|
config = res
|
||||||
|
else
|
||||||
|
config = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
terminals.setup(config)
|
||||||
|
manage.setup(config)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -185,5 +185,8 @@ M.get_length = function()
|
|||||||
return #marked_files
|
return #marked_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.setup = function()
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
87
lua/harpoon/terminal.lua
Normal file
87
lua/harpoon/terminal.lua
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
local Path = require("plenary.path")
|
||||||
|
local cwd = cwd or vim.loop.cwd()
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
harpoon_terminal_config = { }
|
||||||
|
harpoon_terminals = {}
|
||||||
|
harpoon_init = false
|
||||||
|
|
||||||
|
function create_terminal()
|
||||||
|
local current_id = vim.fn.bufnr()
|
||||||
|
|
||||||
|
vim.cmd(":terminal")
|
||||||
|
local buf_id = vim.fn.bufnr()
|
||||||
|
local term_id = vim.b.terminal_job_id
|
||||||
|
|
||||||
|
if term_id == nil then
|
||||||
|
-- TODO: Throw an erro?
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Resets the buffer back to the old one
|
||||||
|
vim.api.nvim_set_current_buf(current_id)
|
||||||
|
return buf_id, term_id
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- First iteration of the setup script
|
||||||
|
lua require("harpoon").setup({
|
||||||
|
terminal: {
|
||||||
|
"/home/theprimeagen/work/netflix": {
|
||||||
|
"yarn build",
|
||||||
|
"yarn test",
|
||||||
|
"yarn dtest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
--]]
|
||||||
|
|
||||||
|
function getCmd(idx)
|
||||||
|
local commandSet = harpoon_terminal_config[cwd]
|
||||||
|
if not commandSet then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return commandSet[idx]
|
||||||
|
end
|
||||||
|
|
||||||
|
M.setup = function(config)
|
||||||
|
harpoon_terminal_config = config.terminal or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
M.gotoTerminal = function(idx)
|
||||||
|
local term_handle = harpoon_terminals[idx]
|
||||||
|
|
||||||
|
if not term_handle then
|
||||||
|
local buf_id, term_id = create_terminal()
|
||||||
|
if buf_id == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
term_handle = {
|
||||||
|
buf_id = buf_id,
|
||||||
|
term_id = term_id
|
||||||
|
}
|
||||||
|
harpoon_terminals[idx] = term_handle
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_buf(term_handle.buf_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.sendCommand = function(idx, cmd)
|
||||||
|
local term_handle = harpoon_terminals[idx]
|
||||||
|
|
||||||
|
if not term_handle then
|
||||||
|
M.gotoTerminal(idx)
|
||||||
|
term_handle = harpoon_terminals[idx]
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(cmd) == "number" then
|
||||||
|
cmd = getCmd(cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
if cmd then
|
||||||
|
vim.fn.chansend(term_handle.term_id, cmd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
8
lua/harpoon/utils.lua
Normal file
8
lua/harpoon/utils.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
local cwd = cwd or vim.loop.cwd()
|
||||||
|
local data_path = vim.fn.stdpath("data")
|
||||||
|
|
||||||
|
local M = {
|
||||||
|
cwd = cwd,
|
||||||
|
data_path,
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
|||||||
com! -nargs=1 Harpoon call harpoon#cmd(<args>)
|
|
||||||
|
|
||||||
augroup THE_PRIMEAGEN_HARPOON
|
augroup THE_PRIMEAGEN_HARPOON
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd VimLeave * :lua require('harpoon.manage-a-mark').save()
|
autocmd VimLeave * :lua require('harpoon.manage-a-mark').save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user