From 3a9b25e6bf49e24794cfb06d1a2e2585f8de2ca9 Mon Sep 17 00:00:00 2001 From: TimUntersberger <32014449+TimUntersberger@users.noreply.github.com> Date: Sat, 12 Sep 2020 23:02:10 +0200 Subject: feat: builtin.commands (#54) * fix: use correct path separator on windows * fix: add utils.get_separator * asdf * feat: add builtin.commands * change commands sorter * change sorter * change sorter --- lua/telescope/builtin.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'lua/telescope/builtin.lua') diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index c4b7cb2..1c3c629 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -56,6 +56,55 @@ builtin.git_files = function(opts) }):find() end +builtin.commands = function() + pickers.new({}, { + prompt = 'Commands', + finder = finders.new_table { + results = (function() + local command_iter = vim.api.nvim_get_commands({}) + local commands = {} + + for _, cmd in pairs(command_iter) do + table.insert(commands, cmd) + end + + return commands + end)(), + entry_maker = function(line) + return { + valid = line ~= "", + entry_type = make_entry.types.GENERIC, + value = line, + ordinal = line.name, + display = line.name + } + end + }, + sorter = sorters.get_generic_fuzzy_sorter(), + attach_mappings = function(prompt_bufnr, map) + local run_command = function() + local selection = actions.get_selected_entry(prompt_bufnr) + actions.close(prompt_bufnr) + local val = selection.value + local cmd = string.format([[:%s ]], val.name) + + if val.nargs == "0" then + vim.cmd(cmd) + else + vim.cmd [[stopinsert]] + vim.fn.feedkeys(cmd) + end + + end + + map('i', '', run_command) + map('n', '', run_command) + + return true + end + }):find() +end + builtin.live_grep = function(opts) opts = opts or {} -- cgit v1.2.3