Skip to content

Commit

Permalink
feat!: new FindCommands
Browse files Browse the repository at this point in the history
  • Loading branch information
LintaoAmons committed Jan 24, 2024
1 parent 3a31e2c commit 1c0748b
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lua/easy-commands/impl/finder.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
local function find_commands()
-- TODO: recent commands
-- local recent_commands = vim.g.easy_command_recent_commands or {}
local commands = vim.api.nvim_get_commands({})

local commandList = {}
local maxLength = 0
for name, value in pairs(commands) do
if #name > maxLength then
maxLength = #name
end
-- if vim.tbl_contains(commandList, value)
table.insert(commandList, value)
end

vim.ui.select(commandList, {
prompt = "Commands",
format_item = function(command)
local name = string.format("%-" .. maxLength .. "s", command.name)
return name .. " | " .. command.definition
end,
telescope = require("telescope.themes"),
}, function(command)
if not command then
return
end
vim.api.nvim_exec2(command.name, {})
end)
end

---@type EasyCommand.Command[]
local M = {
{
Expand All @@ -8,8 +38,7 @@ local M = {
},
{
name = "FindCommands",
callback = "Telescope commands",
dependencies = { "https://github.com/nvim-telescope/telescope.nvim" },
callback = find_commands,
},
{
name = "FindKeymappins",
Expand Down

0 comments on commit 1c0748b

Please sign in to comment.