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
This commit is contained in:
@@ -56,6 +56,55 @@ builtin.git_files = function(opts)
|
|||||||
}):find()
|
}):find()
|
||||||
end
|
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', '<CR>', run_command)
|
||||||
|
map('n', '<CR>', run_command)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}):find()
|
||||||
|
end
|
||||||
|
|
||||||
builtin.live_grep = function(opts)
|
builtin.live_grep = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function make_entry.gen_from_file(opts)
|
|||||||
|
|
||||||
entry_type = make_entry.types.FILE,
|
entry_type = make_entry.types.FILE,
|
||||||
filename = line,
|
filename = line,
|
||||||
path = cwd .. '/' .. line,
|
path = cwd .. utils.get_separator() .. line,
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.display = make_display(line)
|
entry.display = make_display(line)
|
||||||
|
|||||||
@@ -138,4 +138,8 @@ function utils.make_default_callable(f, default_opts)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function utils.get_separator()
|
||||||
|
return package.config:sub(1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|||||||
Reference in New Issue
Block a user