NIVM/lua/plugins/specs/telescope.lua
Robert Morrison fb537df11b chore(init): Initial working version
Create and push an initial working version of this repo before I change
things on this machine

Signed-off-by: Robert Morrison <robert@closedless.xyz>
2023-09-10 22:22:30 +01:00

100 lines
2.5 KiB
Lua

--[[
[ WARNING: This is potential spaghetti code written late at night to solve a problem that has yet to occur...
[ I strongly suggest to anyone reading this (and that means me) to double check what you think it does before
{ making any attempt to edit it
]]
local telescope = {}
telescope.opts = {}
-- default dependencies
telescope.dependencies = { ---@string[]
'nvim-treesitter',
'nvim-web-devicons',
'plenary.nvim',
'popup.nvim',
}
telescope.keys = { ---@LazyKeys[]
-- Keys defined for finding files
{
'<leader>fg',
'<cmd>Telescope live_grep<CR>',
desc = 'Find grep',
},
{
'<leader>fG',
'<cmd>Telescope git_files<CR>',
desc = 'Find git files',
},
-- Misc telescope functions
{
'<leader>tc',
'<cmd>Telescope commands theme=dropdown<CR>',
desc = 'Command Pallet',
},
{
'<leader>ts',
'<cmd>Telescope current_buffer_fuzzy_find<CR>',
desc = 'Fuzzy find in buffer',
},
{
'<leader>tm',
'<cmd>Telescope man_pages sections=1,2,3,4,5,6,7,8,9<CR>',
desc = 'Man',
},
{ '<leader>tt', '<cmd>Telescope builtin<CR>', desc = 'All pickers' },
}
-- This must exist even if we keep it empty for later configuration to work
telescope.opts.opts = {
defaults = {},
pickers = {},
extensions = {},
}
-- TESTS for telescope-media-files
if vim.fn.executable('chafa') then
-- if chafa is installed then we set a flag and add the dependency to telescope
telescope.opts.has_chafa = true
table.insert(telescope.dependencies, 'nvim-telescope/telescope-media-files.nvim')
telescope.opts.opts.extensions.media_files = {
filetypes = { 'png', 'jpg', 'jpeg', 'webp', 'svg' },
}
end
-- TESTS for telescope-fzf-native
-- If not windows then attempt to build and use it.
-- We also check a global flag here that we can set if we can't build fzf-native
if vim.fn.has('win32') == 0 and not vim.g.no_fzf then
-- NOTE: has returns 0 when we don't have a feature
telescope.opts.do_fzf = true
table.insert(telescope.dependencies, 'telescope-fzf-native.nvim')
end
-- TESTS for fzf-native
telescope.config = function(_, opts)
require('telescope').setup()
if opts.has_chafa then require('telescope').load_extension('media_files') end
if opts.do_fzf then require('telescope').load_extension('fzf') end
end
return {
{
'nvim-telescope/telescope.nvim',
cmd = 'Telescope',
opts = telescope.opts,
config = telescope.config,
keys = telescope.keys,
dependencies = telescope.dependencies,
},
{
'nvim-telescope/telescope-fzf-native.nvim',
build = 'make',
cond = function()
return vim.fn.has('win32') == 0 and not vim.g.no_fzf
end,
},
}