Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressing enter will execute the command, pressing <C-r> will filling … #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lua/cheatsheet/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ M.pick_cheat = function(telescope_opts, opts)
return
end

-- Extract command from cheat, eg:
-- ":%bdelete" -> No change
-- ":set hls!" -> No change
-- ":edit [file]" -> ":edit "
-- ":set shiftwidth={n}" -> ":set shiftwidth="
local command = cheat:match("^:[^%[%{]+")
if command ~= nil then
vim.api.nvim_exec(command, true)
else
vim.api.nvim_echo(
{ -- text, highlight group
{ "Cheatsheet [", "" },
{ section, "cheatMetadataSection" },
{ "]: Press ", "" }, { cheat, "cheatCode" },
{ " to ", "" },
{ description:lower(), "cheatDescription" },
}, false, {}
)
end
end
)
map(
'i', '<C-r>', function()
local selection = actions_state.get_selected_entry()
local section = selection.value.section
local description = selection.value.description
local cheat = selection.value.cheatcode

actions.close(prompt_bufnr)

if string.len(cheat) == 1 then
print("Cheatsheet: No command could be executed")
return
end

-- Extract command from cheat, eg:
-- ":%bdelete" -> No change
-- ":set hls!" -> No change
Expand Down