FTerm.nvim
FTerm.nvim copied to clipboard
Why the FTerm not load my fish configuration?
I have defined fish configuration in ~/.config/fish/config.fish(MacOS).
My configuration (Lazy.nvim):
return {
"numToStr/FTerm.nvim",
pin = true,
keys = {
{ "<leader>t", mode = {"n"}, "<CMD>lua require('FTerm').toggle()<CR>"},
{ "<leader>t", mode = {"t"}, "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>"},
},
config = function()
require'FTerm'.setup({
border = 'shadow',
cmd = function()
return 'fish'
end,
dimensions = {
height = 0.7,
width = 0.7,
},
})
end
}
-- EOP
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