nvim/lua/addons/QQdock.lua

38 lines
964 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- addons/QQdock.lua — 持久化自适应终端
--
-- 注意:这是 QQdock.nvim 插件的本地副本(根分区只读,无法通过 lazy 装远程插件)
-- 远程仓库https://git.qyhhh.top/newbie/QQdock.nvim
--
-- 用法:
-- local Q = require('addons.QQdock')
-- Q.shell() -- <c-t> 普通终端
-- Q.open('reasonix') -- <C-i> Reasonix
-- Q.open('lazygit') -- <leader>gg lazygit
local M = {}
local terms = {}
function M.open(cmd)
local ui = vim.api.nvim_list_uis()[1]
if not ui then return end
local tall = ui.height > ui.width
local name = cmd or '__shell__'
if not terms[name] or not terms[name]:is_open() then
terms[name] = require('toggleterm.terminal').Terminal:new({
direction = tall and 'horizontal' or 'vertical',
cmd = cmd,
size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45),
})
end
terms[name]:toggle()
end
function M.shell()
M.open(nil)
end
return M