Skip to content

dimaportenko/project-cli-commands.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

project-cli-commands.nvim


Quickly run your project cli commands with Telescope and ToggleTerm.

demo

Installation

Lazy config

{
  "dimaportenko/project-cli-commands.nvim",

  dependencies = {
    "akinsho/toggleterm.nvim",
    "nvim-telescope/telescope.nvim",
  },

  -- optional keymap config
  config = function()
    local OpenActions = require('project_cli_commands.open_actions')
    local RunActions = require('project_cli_commands.actions')

    local config = {
      -- Key mappings bound inside the telescope window
      running_telescope_mapping = {
        ['<C-c>'] = RunActions.exit_terminal,
        ['<C-f>'] = RunActions.open_float,
        ['<C-v>'] = RunActions.open_vertical,
        ['<C-h>'] = RunActions.open_horizontal,
      },
      open_telescope_mapping = {
        { mode = 'i', key = '<CR>',  action = OpenActions.execute_script_vertical },
        { mode = 'n', key = '<CR>',  action = OpenActions.execute_script_vertical },
        { mode = 'i', key = '<C-h>', action = OpenActions.execute_script },
        { mode = 'n', key = '<C-h>', action = OpenActions.execute_script },
        { mode = 'i', key = '<C-i>', action = OpenActions.execute_script_with_input },
        { mode = 'n', key = '<C-i>', action = OpenActions.execute_script_with_input },
        { mode = 'i', key = '<C-c>', action = OpenActions.copy_command_clipboard },
        { mode = 'n', key = '<C-c>', action = OpenActions.copy_command_clipboard },
        { mode = 'i', key = '<C-f>', action = OpenActions.execute_script_float },
        { mode = 'n', key = '<C-f>', action = OpenActions.execute_script_float },
        { mode = 'i', key = '<C-v>', action = OpenActions.execute_script_vertical },
        { mode = 'n', key = '<C-v>', action = OpenActions.execute_script_vertical },
      }
    }

    require('project_cli_commands').setup(config)
  end
}

Usage

Commands Configuration

Configuration is stored in .nvim/config.json. If you don't have config.json and run Telescope project_cli_commands open it will ask you to create new config for you.

Example of config.json:

{
  "env": ".env",
  "commands": {
    "ls:la": "ls -tls",
    "current:ls": "ls -la ${currentBuffer}",
    "print:env": "echo $EXPO_TOKEN",
    "print:env:local": {
      "cmd": "echo $EXPO_TOKEN",
      "env": ".env.local",
      "after": "Telescope find_files"
    }
  }
}
  • env - (optional) path to the environment file. It will be loaded before running the command.
  • commands - list of termainal commands.
    • key - command name.
    • value - (string) terminal command to run.
    • value - (table) command configuration.
      • cmd - terminal command to run.
      • env - (optional) path to the environment file. It will be loaded before running the command.
      • after - (optional) neovim command to run after the terminal command.

Telescope commands

  • Telescope project_cli_commands open - open telescope with list of commands from config.json. Where you can pick one to run.
  • Telescope project_cli_commands running - open telescope with list of running commands. Where you can toggle terminal for it or stop them.

Keymap

--
vim.api.nvim_set_keymap("n", "<leader>p", ":Telescope project_cli_commands open<cr>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>;", ":Telescope project_cli_commands running<cr>", { noremap = true, silent = true })

Features

Open terminal with command

You can open terminal for command in float, vertical and horizontal mode.

Run command with input

You can run command with input. Basic use case is when you want to add extra arguments to your terminal command.

Copy command to clipboard

By pressing Ctrl+c (default keymap) you can copy command to clipboard.

Run command after

You can run neovim command after terminal command is finished.

Environment variables

You can load environment variables from file before running the command.

Inject current buffer path to command

For example you would like to run test for current buffer you can configure it like this

{
  "commands": {
    "test:current": "jest ${currentBuffer}"
  }
}

List of running commands

You can open list of running commands with Telescope project_cli_commands running. There you can show/hide terminal for each command. Or you can stop running command.

TODO

  • keymap open toggleterm with different positions (e.g. float like rnstart cmd)

  • merge telescope-toggleterm plugin with this one

  • add vertical open option

  • add keymaps config

  • add new config templates setup

  • add environment variables to run commands

  • table config for commands

  • after command (e.g. run 'LspRestart' after terminal command)

  • current directory path variable ${currentDirectory}

  • scroll preview content

  • copy to clipboard with ${currentBuffer}

  • add readme

    • add installation instructions
    • keymaps setup
    • features description and examples
    • demo gif
    • full demo video (maybe on youtube)

About

Quickly run cli commands for your project in NeoVim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages