numToStr / FTerm.nvim

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

[Feature Request] Allow functions in `cmd` #63

Closed luiz00martins closed 1 year ago

luiz00martins commented 1 year ago

I'm trying to run a terminal with 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit' everytime the terminal is (re)opened. This is not currently possible, as the cmd is only evaluated upon creation.

It would be nice if the I could use a function instead of a string on cmd, which would be called on every startup of the terminal:

require("FTerm"):new({
    ...
    cmd = function() return 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit' end,
    ...
})

Note: I'm posting this request because terminal:run() won't suffice, as run will re-run the command on every execution, while setting cmd would only re-run the command when the terminal is closed and reopened.

numToStr commented 1 year ago

Great Idea! I'll add support for function in cmd.

luiz00martins commented 1 year ago

Thanks @numToStr. I'm still having some difficulties.

Do you know the reason why cmd = function() return 'cd "'..vim.fn.expand('%:p:h')..'" ; lazygit' end isn't working?

What I mean by that is that the lazygit command is not executed inside the cd'ed folder (you can confirm this by using cmd = function() return 'cd "'..vim.fn.expand('%:p:h')..'" ; bash' end instead, in which bash will not start in the folder).

numToStr commented 1 year ago

@luiz00martins Looks like you are running multiple commands. But :h termopen (which uses jobstart) only supports single command.

luiz00martins commented 1 year ago

:cry: