Home

Awesome

tmutils.nvim


   ██                         ██   ██  ██                              ██
  ░██                        ░██  ░░  ░██                             ░░
 ██████ ██████████  ██   ██ ██████ ██ ░██  ██████    ███████  ██    ██ ██ ██████████
░░░██░ ░░██░░██░░██░██  ░██░░░██░ ░██ ░██ ██░░░░    ░░██░░░██░██   ░██░██░░██░░██░░██
  ░██   ░██ ░██ ░██░██  ░██  ░██  ░██ ░██░░█████     ░██  ░██░░██ ░██ ░██ ░██ ░██ ░██
  ░██   ░██ ░██ ░██░██  ░██  ░██  ░██ ░██ ░░░░░██ ██ ░██  ░██ ░░████  ░██ ░██ ░██ ░██
  ░░██  ███ ░██ ░██░░██████  ░░██ ░██ ███ ██████ ░██ ███  ░██  ░░██   ░██ ███ ░██ ░██
   ░░  ░░░  ░░  ░░  ░░░░░░    ░░  ░░ ░░░ ░░░░░░  ░░ ░░░   ░░    ░░    ░░ ░░░  ░░  ░░

tmutils.nvim is a Neovim plugin designed to streamline common development tasks that involve both tmux and Neovim. Key features include:

For a more detailed guide and documentation, review the help page: :help tmutils.txt

Installation


Usage


A comprehensive usage guide can be read in the help page: :help tmutils-usage. However, here are some examples of it:

Configuration


The configuration table has the following schema (review LuaLS type specification for the type annotations):

{
    --Configuration for UI-based selection.
    selector = {
        --The backend used to select options.
        selector = [[
        fun(
            opts: string[],
            message: string,
            callback: fun(selected_opt: string): nil
            ): nil
        ]]
        },
    --Configuration for the scratch window.
    scratch = {
        --Scratch window width.
        width = "integer"
        --Scratch window height.
        height = "integer"
        --Scratch window center col.
        col = "integer",
        --Scratch window center row.
        row = "integer",
        --Scratch window border.
        border = "none" | "single" | "double" | "rounded" | "solid" | "shadow",
        --Scratch window title position.
        title_pos = "center" | "left" | "right"
        },
    --Configuration for window management commands.
    window = {
        --Configuration for the terminal pane.
        terminal = {
            --Direction in which to split the terminal pane.
            direction = '"vertical" | "horizontal"',
            --Relative size (in percentage) for the terminal pane.
            size = 'number',
            --Function that returns a list of commands to be executed
            --when launching a new terminal pane.
            commands = 'fun(): string[]'
            },
        repls = {
            --Assign a key to the repl
            repl1 = {
                --Direction in which to split the repl pane.
                direction = '"vertical" | "horizontal"',
                --Relative size (in percentage) for the repl pane.
                size = 'number',
                --Function that returns a list of commands to be executed
                --when launching a new repl pane.
                commands = 'fun(): string[]'
                },
            --Assign a key to the repl
            repl2 = {
                --Direction in which to split the repl pane.
                direction = '"vertical" | "horizontal"',
                --Relative size (in percentage) for the repl pane.
                size = 'number',
                --Function that returns a list of commands to be executed
                --when launching a new repl pane.
                commands = 'fun(): string[]'
                },
            --Create other repls following the same structure.
            }
        }
    }

Let's see a full example configuration using lazy.nvim with the following features:

{
	"juselara1/tmutils.nvim",
	dependencies = {
        "nvim-telescope/telescope.nvim",
    },
	config = function()
		local selectors = require("tmutils.selectors")
		require("tmutils").setup {
			selector = {
				selector = selectors.telescope_selector
			},
			window = {
				repls = {
					python = {
						syntax = "python",
						commands = function()
							return {
								("cd %s"):format(vim.fn.getcwd()),
								"clear",
								"python",
							}
						end
					},
					ipython = {
						syntax = "python",
						commands = function()
							return {
								("cd %s"):format(vim.fn.getcwd()),
								"ipython",
								"clear",
							}
						end
					},
					compose = {
						syntax = "sh",
						commands = function()
							return {
								("cd %s"):format(vim.fn.getcwd()),
								"docker compose up -d",
								"docker exec -it `docker compose config --services` bash",
								"clear"
							}
						end
					}
				}
			}
		}

		vim.keymap.set(
			'n', "<leader>tc", ":TmutilsConfig<CR>",
			{
				noremap = true, silent=true,
				desc="Setups the Tmutils pane."
				}
			)
		vim.keymap.set(
			'n', "<leader>ta", ":TmutilsCapture newbuffer<CR>",
			{
				noremap = true, silent=true,
				desc="Captures the content of a Tmutils pane."
				}
			)
		vim.keymap.set(
			'n', "<leader>tt", ":TmutilsWindow terminal<CR>",
			{
				noremap = true, silent=true,
				desc="Launches a Tmutils terminal."
				}
			)
		vim.keymap.set(
			'n', "<leader>tr", ":TmutilsWindow repl<CR>",
			{
				noremap = true, silent=true,
				desc="Shows a menu to select and launch a Tmutils repl."
				}
			)
		vim.keymap.set(
			'n', "<leader>td", ":TmutilsWindow delete<CR>",
			{
				noremap = true, silent=true,
				desc="Deletes the configured Tmutils pane."
				}
			)
		vim.keymap.set(
			'n', "<leader>ts", ":TmutilsScratchToggle<CR>",
			{
				noremap = true, silent=true,
				desc="Opens Tmutils Scratch"
				}
			)
		vim.keymap.set(
			'n', "<leader>tx", function ()
				vim.cmd("norm vix")
				local pos_l = vim.fn.getpos('.')
				local pos_r = vim.fn.getpos('v')
				vim.cmd(("%d,%dTmutilsSend"):format(pos_l[2], pos_r[2]))
				vim.api.nvim_input("<Esc>")
			end,
			{
				noremap = true, silent=true,
				desc="Sends a code cell to a Tmutils pane."
				}
			)
		vim.keymap.set(
			'n', "<leader>tl", ":.TmutilsSend<CR>",
			{
				noremap = true, silent=true,
				desc="Sends a visual selection to a Tmutils pane."
				}
			)
		vim.keymap.set(
			'v', "<leader>tv", ":TmutilsSend<CR>",
			{
				noremap = true, silent=true,
				desc="Sends a visual selection to a Tmutils pane."
				}
			)
	end
}