Skip to content

guaging interest in a open_and_run convenience function #34

@audibleblink

Description

@audibleblink

Thanks for exposing the methods necessary to be able to do this.
Is having this functionality built-in within scope of this project?

If so, let me know of any parameters/constraints I should be aware of before making the PR.

local function run_in_floaterm(opts)
	local buf = 0

    -- open first, otherwise window_id's dont exist and `switch_buf` will fail
	require("floaterm").open()

	for _, term in ipairs(require("floaterm.state").terminals) do
		if term.name == opts.name then
			buf = term.buf
			break
		end
	end

	if buf == 0 then
		require("floaterm.api").new_term({ cmd = opts.cmd, name = opts.name })
	else
		require("floaterm.api").send_cmd({ cmd = opts.cmd, buf = buf })
		require("floaterm.utils").switch_buf(buf)
	end
end

vim.keymap.set("n", "<leader>gP", function()
	run_in_floaterm({ name = "Git", cmd = "git push" })
end, { desc = "Floaterm: Git Push" })

Could maybe be exposed as:

require("floaterm.api").open_and_run({ name = "Git", cmd = "git push"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions