-
-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathtoggleterm.lua
More file actions
110 lines (109 loc) · 5.07 KB
/
toggleterm.lua
File metadata and controls
110 lines (109 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
return {
"akinsho/toggleterm.nvim",
cmd = { "ToggleTerm", "TermExec" },
specs = {
{
"AstroNvim/astrocore",
opts = function(_, opts)
local maps = opts.mappings
local astro = require "astrocore"
maps.n["<Leader>t"] = vim.tbl_get(opts, "_map_sections", "t")
if vim.fn.executable "git" == 1 and vim.fn.executable "lazygit" == 1 then
maps.n["<Leader>g"] = vim.tbl_get(opts, "_map_sections", "g")
local lazygit = {
callback = function()
local worktree = astro.file_worktree()
local flags = worktree and (" --work-tree=%s --git-dir=%s"):format(worktree.toplevel, worktree.gitdir)
or ""
astro.toggle_term_cmd { cmd = "lazygit " .. flags, direction = "float" }
end,
desc = "ToggleTerm lazygit",
}
maps.n["<Leader>gg"] = { lazygit.callback, desc = lazygit.desc }
maps.n["<Leader>tl"] = { lazygit.callback, desc = lazygit.desc }
end
if vim.fn.executable "node" == 1 then
maps.n["<Leader>tn"] = { function() astro.toggle_term_cmd "node" end, desc = "ToggleTerm node" }
end
local gdu = "gdu"
if vim.fn.executable(gdu) ~= 1 then
if vim.fn.has "win32" == 1 then
gdu = "gdu_windows_amd64.exe"
elseif vim.fn.has "mac" == 1 then
gdu = "gdu-go"
end
end
if vim.fn.executable(gdu) == 1 then
maps.n["<Leader>tu"] =
{ function() astro.toggle_term_cmd { cmd = gdu, direction = "float" } end, desc = "ToggleTerm gdu" }
end
if vim.fn.executable "btm" == 1 then
maps.n["<Leader>tt"] =
{ function() astro.toggle_term_cmd { cmd = "btm", direction = "float" } end, desc = "ToggleTerm btm" }
end
local python = vim.fn.executable "python" == 1 and "python" or vim.fn.executable "python3" == 1 and "python3"
if python then
maps.n["<Leader>tp"] = { function() astro.toggle_term_cmd(python) end, desc = "ToggleTerm python" }
end
maps.n["<Leader>tf"] = { "<Cmd>ToggleTerm direction=float<CR>", desc = "ToggleTerm float" }
maps.n["<Leader>th"] =
{ "<Cmd>ToggleTerm size=10 direction=horizontal<CR>", desc = "ToggleTerm horizontal split" }
maps.n["<Leader>tv"] = { "<Cmd>ToggleTerm size=80 direction=vertical<CR>", desc = "ToggleTerm vertical split" }
maps.n["<F7>"] = { '<Cmd>execute v:count . "ToggleTerm"<CR>', desc = "Toggle terminal" }
maps.t["<F7>"] = { "<Cmd>ToggleTerm<CR>", desc = "Toggle terminal" }
maps.i["<F7>"] = { "<Esc><Cmd>ToggleTerm<CR>", desc = "Toggle terminal" }
maps.n["<C-'>"] = { '<Cmd>execute v:count . "ToggleTerm"<CR>', desc = "Toggle terminal" } -- requires terminal that supports binding <C-'>
maps.t["<C-'>"] = { "<Cmd>ToggleTerm<CR>", desc = "Toggle terminal" } -- requires terminal that supports binding <C-'>
maps.i["<C-'>"] = { "<Esc><Cmd>ToggleTerm<CR>", desc = "Toggle terminal" } -- requires terminal that supports binding <C-'>
end,
},
{
"nvim-neo-tree/neo-tree.nvim",
optional = true,
opts = function(_, opts)
if not opts.commands then opts.commands = {} end
if not opts.window then opts.window = {} end
if not opts.window.mappings then opts.window.mappings = {} end
local function toggleterm_in_direction(state, direction)
local node = state.tree:get_node()
local path = node.type == "file" and node:get_parent_id() or node:get_id()
require("toggleterm.terminal").Terminal:new({ dir = path, direction = direction }):toggle()
end
local prefix = "T"
---@diagnostic disable-next-line: assign-type-mismatch
opts.window.mappings[prefix] =
{ "show_help", nowait = false, config = { title = "New Terminal", prefix_key = prefix } }
for suffix, direction in pairs { f = "float", h = "horizontal", v = "vertical" } do
local command = "toggleterm_" .. direction
opts.commands[command] = function(state) toggleterm_in_direction(state, direction) end
opts.window.mappings[prefix .. suffix] = command
end
end,
},
},
opts = {
highlights = {
Normal = { link = "Normal" },
NormalNC = { link = "NormalNC" },
NormalFloat = { link = "NormalFloat" },
FloatBorder = { link = "FloatBorder" },
StatusLine = { link = "StatusLine" },
StatusLineNC = { link = "StatusLineNC" },
WinBar = { link = "WinBar" },
WinBarNC = { link = "WinBarNC" },
},
size = 10,
---@param t Terminal
on_create = function(t)
vim.opt_local.foldcolumn = "0"
vim.opt_local.signcolumn = "no"
if t.hidden then
local function toggle() t:toggle() end
vim.keymap.set({ "n", "t", "i" }, "<C-'>", toggle, { desc = "Toggle terminal", buffer = t.bufnr })
vim.keymap.set({ "n", "t", "i" }, "<F7>", toggle, { desc = "Toggle terminal", buffer = t.bufnr })
end
end,
shading_factor = 2,
float_opts = { border = "rounded" },
},
}