numToStr / FTerm.nvim

:fire: No-nonsense floating terminal plugin for neovim :fire:
MIT License
721 stars 24 forks source link

Launch terminal with command #6

Closed chmln closed 3 years ago

chmln commented 3 years ago

It would be great to have the ability to pass a command to a floating terminal. I would use this to launch lazygit with a single keybind.

numToStr commented 3 years ago

This feature was also in my mind. But I think I might need to implement multiple terminals instances first as currently It only supports only one terminal instance.

EpsilonKu commented 3 years ago

So I found function "chansend()" which can send argument to terminal (https://neovim.io/doc/user/channel.html). I guess it will help you.

numToStr commented 3 years ago

As it turns out this was fairly easy to implement, I just need to allow the run command to be customizable. You just need to use the underlying terminal function to make this work. Just switch to the multi branch to test it out give your initial feedback. If you have anything else on your mind do let me know.

And also sorry for the delay :)

Example

local term = require("FTerm.terminal")

-- Opening bashtop
local bashtop = term:new()

bashtop:setup({cmd = "bashtop"})

function _G.__fterm_bashtop()
    bashtop:toggle()
end

-- Opening gitui
local gitui = term:new()

gitui:setup({cmd = "gitui"})

function _G.__fterm_gitui()
    gitui:toggle()
end

In Action

https://user-images.githubusercontent.com/24727447/113911583-c2738900-97f7-11eb-8a01-22918b333572.mp4

Just ignore the broken highlights in gitui

EpsilonKu commented 3 years ago

That's good. What about to make symbols (like % in Floaterm) to send file name.

numToStr commented 3 years ago

I am not sure about the vim character like %, $. But you can use the lua API like vim.api.nvim_get_current_buf() which I think is same as %.