/execa.nvim

Execute commands with variables driven by treesitter

Primary LanguageLua

Execa.nvim

This is a simple plugin to run shell commands in a terminal buffer with access to many different "variables".

Installation

Using lazy.nvim

{
  "d4rkr00t/execa.nvim",
  cmd = "Execa",
  opts = {
    -- Open terminal in a vertical or horizontal split
    split = "vsplit",

    -- Prints the command before running
    verbose = true,

    -- Ask for confirmation before running a command
    confirm = true,

    -- A list of pre-defined commands
    commands = {
      hello = "echo $EX_FN",
    }
  }
}

Usage

Variables

  • $EX_FN – Current function name (powered by treesitter)
  • $EX_STR – Content of the string under the cursor (powered by treesitter)
  • $EX_FILE_PATH_REL – Relative path to the current file
  • $EX_FILE_PATH – Absolute path to the current file
  • $EX_FILE_NAME_NO_EXT – Current file name without extension
  • $EX_FILE_NAME – Current file name
  • $EX_DIR_PATH – Current dir path
  • $EX_DIR_NAME – Current dir name
  • $EX_LINE – Current line number
  • $EX_COL – Current col number

Run

Runs a command in a terminal buffer.

:Execa run echo $EX_FN

Outputs the current function name.

Repeat

Repeats the last command in the current context. It runs the same command but re-evaluates the variables.

:Execa repeat

Command

Runs a pre-defined command in a terminal buffer.

:Execa command hello

Telescope Integration

Opens a telescope picker with a list of pre-defined commands.

:Execa telescope

Examples

Run single test with cargo

:Execa run cargo test $EX_FN

Execa Cargo Test

Get the latest version of a package from npm

:Execa run npm view $EX_STR version

Execa NPM