Git Product home page Git Product logo

telescope-runcmd.nvim's Introduction

RunCMD Telescope extension

runcmd

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: functions provided by the builtin lsp server

Examples

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'"))
end


vim.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 <leader>cmd
vim.keymap.set("n", "<leader>cmd", ":Telescope runcmd<cr>", {buffer = true})

telescope-runcmd.nvim's People

Contributors

ajnasz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.