numToStr / FTerm.nvim

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

Add argument to cmd options #39

Closed duyanh-y4n closed 3 years ago

duyanh-y4n commented 3 years ago

Hi all,

I love the scratch terminal and have used it forever since its release. Very fast and super useful.

Still, I need the ability to pass the arguments along with cmd option in config. My example use case would be like this

-- debug current python script
vim.cmd('command! Pudb lua require("FTerm").scratch({ cmd = "pudb" args = "%" })')

Of course, "%" is a vim feature for expanding the current filename. I haven't had much experience with vim API in lua yet. Maybe some of you guys know how to do it right away and have some suggesting idea. I think this feature could add even more flexibility to Fterm.

Thank you in advance!

numToStr commented 3 years ago

I am glad that you are enjoying this plugin.

To be honest, proper argument support is on the back of my mind and I do want to add this. But I am not planning to support VimL stuff like %. For your use case, you can do something like this with the Lua API

vim.cmd('command! Pudb lua require("FTerm").scratch({ cmd = "pudb "..vim.api.nvim_buf_get_name(0) })')

Here vim.api.nvim_buf_get_name(0) is roughly equivalent to %


Onto what's on my mind regarding arguments. I am considering the following.


-- # 1. cmd: { string, string }, where first item is the `command` and rest is arguments to that command 
require("FTerm").scratch({ cmd = { "yarn", "build" } })
require("FTerm").scratch({ cmd = { "node", vim.api.nvim_buf_get_name(0) } })
require("FTerm").scratch({ cmd = { "jq", ".[]", vim.api.nvim_buf_get_name(0) } })

-- # 2. cmd: { string, string{} }, where first item is the `command` and second table is the arguments to that command
require("FTerm").scratch({ cmd = { "git", { "commit", "-a", "-m", "this is a commit" } } })

-- # 3. cmd: string, args: string{}, where `cmd` is the actual command and `args` is the arguments to that command.
require("FTerm").scratch({ cmd = "git", args = { "commit", "-a", "-m", "this is a commit" }  })

And I am most likely to implement the first one. If you have any thoughts I would like to hear it.

duyanh-y4n commented 3 years ago

Thanks for the tips! It works for me.