Open jonahfang opened 8 months ago
I now must exec following cmd after open the terminal, anyway to exec automatically?
I have got solution to this problem : send text to teminal after it opened:
return {
"numToStr/FTerm.nvim",
pin = true,
lazy = false,
config = function()
local fterm = require("FTerm")
local m = require('utils.terminal')
fterm.setup({
border = 'single',
dimensions = {
height = 0.7,
width = 1.0,
x = 0,
y = 0,
},
})
-- first terminal
local opened_1 = 0
vim.api.nvim_create_user_command('FirstFishFTerminal', function()
fterm.toggle()
if opened_1 == 0 then
m.terminal_send('source ~/fish\nc\n',1)
opened_1 = 1
end
end, { bang = true })
vim.keymap.set('n', '<leader>t', "<CMD>FirstFishFTerminal<CR>")
vim.keymap.set('t', '<leader>t', "<C-\\><C-n><CMD>FirstFishFTerminal<CR>")
...
and the utils.terminal.lua like this:
-- Thanks:https://www.reddit.com/r/neovim/comments/ojnl86/how_to_send_commands_to_the_integrated_terminal/
local M = {}
function get_terminal(n)
terminal_chans = {}
for _, chan in pairs(vim.api.nvim_list_chans()) do
if chan["mode"] == "terminal" and chan["pty"] ~= "" then
table.insert(terminal_chans, chan)
end
end
table.sort(terminal_chans, function(left, right)
return left["buffer"] < right["buffer"]
end)
return terminal_chans[n]["id"]
end
function M.terminal_send(text,n)
first_terminal_chan = get_terminal(n)
vim.api.nvim_chan_send(first_terminal_chan, text)
end
return M
-- EOP
I have defined fish configuration in
~/.config/fish/config.fish
(MacOS).My configuration (Lazy.nvim):