https://github.com/ajnasz/telescope-runcmd.nvim
run commands from neovim telescope
https://github.com/ajnasz/telescope-runcmd.nvim
neovim neovim-plugin nvim nvim-telescope telescope telescope-extension
Last synced: 6 months ago
JSON representation
run commands from neovim telescope
- Host: GitHub
- URL: https://github.com/ajnasz/telescope-runcmd.nvim
- Owner: Ajnasz
- License: mit
- Created: 2024-01-05T11:05:31.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-12T12:03:00.000Z (10 months ago)
- Last Synced: 2025-03-24T16:41:01.459Z (7 months ago)
- Topics: neovim, neovim-plugin, nvim, nvim-telescope, telescope, telescope-extension
- Language: Lua
- Homepage:
- Size: 53.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# RunCMD Telescope extension

## Usage
The extension loads commands from `vim.g.runcmd_commands`,
`vim.w.runcmd_commands` and `vim.b.runcmd_commands`.
A command must have a `name` property, which will be displayed in the telescope
window. A `cmd` property which will be executed when the item selected and an
optional `description` which will be also displayed in the telescope window
next to the name.A `cmd` can be a lua function or a user command as string.
To open the configured commands, use `:Telescope runcmd` command.
With the `FileType` autocommand you can add commands only for specific filetypes by adding commands to `vim.b.runcmd_commands`.
You can use the `require("runcmd.picker").open({ results = { ... }})` to open the picker with any command.
For more see the examples below
## Predefined commands
Some predfined commands provided by the plugin:
- [lsp](fnl/runcmd/commands/lsp.fnl): functions provided by the builtin lsp server
## Examples
```lua
local runcmd = require("runcmd")
local telescope = require("telescope")-- general wrapper to put string to the cursor
function insert_at_cursor(lines)
return vim.api.nvim_put(lines, "", false, true)
end-- function to insert the current date to the cursor with the given format
function insert_date_str(format)
return insert_at_cursor({vim.fn.strftime(format)})
end-- insert uuid to the cursor position
function insert_uuid()
return insert_at_cursor(vim.fn.systemlist("uuid | tr -d '\n'"))
endvim.api.nvim_create_user_command("UUID", insert_uuid, {})
-- global commands
vim.g.runcmd_commands = {
-- lua function command
{ name = "UUID", cmd = insert_uuid, description = "Insert UUID" },
{ name = "Date", cmd = function() insert_date_str("%Y-%m-%d") end, description = "Insert date" },
{ name = "Time", cmd = function() insert_date_str("%H-%M-%S") end, description = "Insert time" },
{ name = "Date Time", cmd = function() insert_date_str("%Y-%d-%m %H-%M-%S") end, description = "Insert date time" },
-- predefined user command (vim-fugitive)
{ name = "Git", cmd = "Git", description = "Open Git" },
-- subcommands
{
name = "Lsp ->",
cmd = function()
local picker = require('runcmd.picker')
picker.open({
results = require('runcmd.commands.lsp'),
})
end,
description = "Language Server commands",
},
}-- commands for specific filetype
vim.api.nvim_create_autocmd({ "FileType" }, {
pattern = {"ledger"},
callback = function()
vim.b.runcmd_commands = {
{
name = "Align Buffer",
cmd = "LedgerAlignBuffer",
description = "Aligns the commodity for each posting in the entire buffer",
},
}
end
})
telescope.load_extension("runcmd")-- map to hotkey key cmd
vim.keymap.set("n", "cmd", ":Telescope runcmd", {buffer = false})
```