mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
custom terminal creation command
This commit is contained in:
parent
55d5d808d6
commit
6dfcc07aa3
@ -4,11 +4,14 @@ local log = require("harpoon.dev").log
|
|||||||
local M = {}
|
local M = {}
|
||||||
local terminals = {}
|
local terminals = {}
|
||||||
|
|
||||||
local function create_terminal()
|
local function create_terminal(create_cmd)
|
||||||
log.trace("_create_terminal()")
|
if not create_cmd then
|
||||||
|
create_cmd = ":terminal"
|
||||||
|
end
|
||||||
|
log.trace("_create_terminal(): Init:", create_cmd)
|
||||||
local current_id = vim.fn.bufnr()
|
local current_id = vim.fn.bufnr()
|
||||||
|
|
||||||
vim.cmd(":terminal")
|
vim.cmd(create_cmd)
|
||||||
local buf_id = vim.fn.bufnr()
|
local buf_id = vim.fn.bufnr()
|
||||||
local term_id = vim.b.terminal_job_id
|
local term_id = vim.b.terminal_job_id
|
||||||
|
|
||||||
@ -27,11 +30,11 @@ local function create_terminal()
|
|||||||
return buf_id, term_id
|
return buf_id, term_id
|
||||||
end
|
end
|
||||||
|
|
||||||
local function find_terminal(idx)
|
local function find_terminal(idx, create_cmd)
|
||||||
log.trace("_find_terminal(): Terminal:", idx)
|
log.trace("_find_terminal(): 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(create_cmd)
|
||||||
if buf_id == nil then
|
if buf_id == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -45,24 +48,27 @@ local function find_terminal(idx)
|
|||||||
return term_handle
|
return term_handle
|
||||||
end
|
end
|
||||||
|
|
||||||
M.gotoTerminal = function(idx)
|
M.gotoTerminal = function(idx, create_cmd)
|
||||||
log.trace("gotoTerminal(): Terminal:", idx)
|
log.trace("gotoTerminal(): Terminal:", idx)
|
||||||
local term_handle = find_terminal(idx)
|
local term_handle = find_terminal(idx, create_cmd)
|
||||||
|
|
||||||
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, create_cmd)
|
||||||
log.trace("sendCommand(): Terminal:", idx)
|
log.trace("sendCommand(): Terminal:", idx)
|
||||||
local term_handle = find_terminal(idx)
|
local term_handle = find_terminal(idx, create_cmd)
|
||||||
|
|
||||||
if type(cmd) == "number" then
|
if type(cmd) == "number" then
|
||||||
cmd = harpoon.get_term_config().cmds[cmd]
|
cmd = harpoon.get_term_config().cmds[cmd]
|
||||||
end
|
end
|
||||||
|
if type(cmd) == "string" then
|
||||||
|
cmd = {cmd}
|
||||||
|
end
|
||||||
|
|
||||||
if cmd then
|
if cmd then
|
||||||
log.debug("sendCommand:", cmd)
|
log.debug("sendCommand:", cmd[1])
|
||||||
vim.fn.chansend(term_handle.term_id, string.format(cmd, ...))
|
vim.fn.chansend(term_handle.term_id, string.format(unpack(cmd)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user