Closed ayoubelmhamdi closed 3 years ago
hmmmmm you can do something like this
local action_set = require "telescope.actions.set"
local actions = require "telescope.actions"
local glowPreviewer = function()
return require'telescope.builtin'.fd {
attach_mappings = function(prompt_bufnr)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if cmd == "default" or cmd == "horizontal" then
vim.cmd("term glow " .. selection.value)
elseif cmd == "vertical" then
vim.cmd("vs | term glow " .. selection.value)
end)
return true
end,
}
end
If you want more and would like to preview with glow on telescope buffer.
local previewers = require('telescope.previewers')
local glow_previewer = function()
return require'telescope.builtin'.fd {
previewer = previewers.new_termopen_previewer {
get_command = function(selection)
return { 'glow', selection.value }
end
}
}
end
Just want to follow up on this issue. I am new to configuring telescope.
How would you actually go about applying this custom previewer to the builtin.find_files but only for markdown files. Just wondering what the best way to implement this would be?
I have tried to find a resource on how do this, but no luck.
Some guidance would be much appreciated
To use glow.nvim, could probably utilize the TelescopePreviewLoaded
autocommand event.
I haven't tested this and I barely know anything about glow but maybe something like this could work?
vim.api.nvim_create_autocmd("User", {
pattern = "TelescopePreviewerLoaded",
callback = function(args)
if args.data.filetype == "markdown" then
vim.cmd("Glow")
end
end,
})
Just tried this auto-command and found that it throws an error saying: attempt to index field 'data' (a nil value). From the "args" table.
Is there a simple way of implementing @kkharji 's code:
local previewers = require('telescope.previewers')
local glow_previewer = function()
return require'telescope.builtin'.fd {
previewer = previewers.new_termopen_previewer {
get_command = function(selection)
return { 'glow', selection.value }
end
}
}
end
into my telescope configuration?
How would I setup my telescope previewer to run this function?
I just don't know how to setup up custom previewers in telescope. (Maybe I should ask this in telescope.nvim repo)
I would use this plugin to pick a file and open it by glow.nvim (MarkdownPreview) like this: