-
I'm migrating my Run the plugin to show a picker with the pre-filled command (search from the current folder e.g. *.sh) and fill into the picker, user can pick the command to run. Also, user is able to type the new command to run and add it the command list as well. But I can't find a way to get back the user input... any idea?:) Here is how I call -- `CMD_LIST` is a string array
require('fzf-lua').fzf_exec(CMD_LIST, {
prompt = " Project commands ('ctrl+d' to delete item) ",
winopts = {
width = 0.50,
height = 0.40,
},
actions = {
["default"] = function(selected)
if (enable_debug_print) then
print(string.format(
">>> selected: %s, type: %s",
vim.inspect(selected),
type(selected)
))
end
--
-- >>>> Question: How to do I get back the user command from the picker's input???
-- >>>> Question: How to do I get back the user command from the picker's input???
-- >>>> Question: How to do I get back the user command from the picker's input???
--
-- execute_command_v2(user_input_command)
end,
--
-- `ctrl+d` to delete selected item
--
["ctrl-d"] = function(selected)
if (enable_debug_print) then
print(string.format(
">>> selected to be deleted: %s, type: %s",
vim.inspect(selected),
type(selected)
))
end
if #selected <= 0 then return end
local index_to_delete = -1
for index, value in ipairs(CMD_LIST) do
if value == vim.trim(selected[1]) then
index_to_delete = index
break
end
end
if index_to_delete ~= -1 then
table.remove(CMD_LIST, index_to_delete)
end
--- Resume (also refresh the UI)
require('fzf-lua').actions.resume()
end,
},
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Use opts.last_query from the second arg of the function callback: actions = {
["enter"] = function(selected, opts)
-- user input is in opts.last_query For more info see how fzf-lua git branch add bind works: fzf-lua/lua/fzf-lua/actions.lua Lines 799 to 817 in 3e644b8 |
Beta Was this translation helpful? Give feedback.
-
hello @ibhagwan, it works correctly when we use an action. however, is it possible to retrieve user input from the keymap? keymap = {
fzf = {
["a"] = function(opts)
require('utils.func').debug(opts)
end,
},
} |
Beta Was this translation helpful? Give feedback.
Use opts.last_query from the second arg of the function callback:
For more info see how fzf-lua git branch add bind works:
fzf-lua/lua/fzf-lua/actions.lua
Lines 799 to 817 in 3e644b8