aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/telescope.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/plugins/telescope.lua')
-rw-r--r--.config/nvim/lua/plugins/telescope.lua513
1 files changed, 309 insertions, 204 deletions
diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua
index 079f88b..0167aa3 100644
--- a/.config/nvim/lua/plugins/telescope.lua
+++ b/.config/nvim/lua/plugins/telescope.lua
@@ -1,91 +1,93 @@
local M = {}
-- Shorten function names
-local actions = require("telescope.actions")
-local fb_actions = require("telescope").extensions.file_browser.actions
+local actions = require('telescope.actions')
+local fb_actions = require('telescope').extensions.file_browser.actions
--local builtin = require("telescope.builtin")
---local themes = require("telescope.themes")
--local utils = require("telescope.utils")
---local action_state = require("telescope.actions.state")
--local layout_actions = require("telescope.actions.layout")
---local pickers = require("telescope.pickers")
-local themes = require("telescope.themes")
-
+--local themes = require('telescope.themes')
+local actions_set = require('telescope.actions.set')
+local actions_state = require('telescope.actions.state')
+local finders = require('telescope.finders')
+local pickers = require('telescope.pickers')
+local config = require('telescope.config').values
require('telescope').setup({
defaults = {
vimgrep_arguments = {
- "rg",
- "--color=never",
- "--no-heading",
- "--with-filename",
- "--line-number",
- "--column",
- "--smart-case",
- "--hidden",
- "--fixed-strings",
- "--trim",
+ 'rg',
+ '--color=never',
+ '--no-heading',
+ '--with-filename',
+ '--line-number',
+ '--column',
+ '--smart-case',
+ '--hidden',
+ '--fixed-strings',
+ '--trim',
},
- prompt_prefix = " ",
- selection_caret = " ",
- entry_prefix = " ",
- path_display = { "tail" },
+ prompt_prefix = ' ',
+ selection_caret = ' ',
+ entry_prefix = ' ',
+ path_display = { 'tail' },
--path_display = { "truncate" },
--path_display = { "smart" },
file_ignore_patterns = {
- "packer_compiled.lua",
- "zcompdump",
- "%.DS_Store",
- "%.git/",
- "%.spl",
+ 'packer_compiled.lua',
+ '~/.config/zsh/plugins',
+ 'zcompdump',
+ '%.DS_Store',
+ '%.git/',
+ '%.spl',
--"%.log",
- "%[No Name%]", -- new files / sometimes folders (netrw)
- "/$", -- ignore folders (netrw)
- "node_modules",
- "%.png",
- "%.zip",
- "%.pxd",
- "^.vim/",
- "^.local/",
- "^.cache/",
- "^downloads/",
- "^music/",
+ '%[No Name%]', -- new files / sometimes folders (netrw)
+ '/$', -- ignore folders (netrw)
+ 'node_modules',
+ '%.png',
+ '%.zip',
+ '%.pxd',
+ --"^.vim/",
+ '^.local/',
+ '^.cache/',
+ '^downloads/',
+ '^music/',
--"^node_modules/",
--"^undodir/",
},
mappings = {
i = {
- ["<C-n>"] = actions.cycle_history_next,
- ["<C-p>"] = actions.cycle_history_prev,
+ ['<C-n>'] = actions.cycle_history_next,
+ ['<C-p>'] = actions.cycle_history_prev,
- ["<C-j>"] = actions.move_selection_next,
- ["<C-k>"] = actions.move_selection_previous,
+ ['<C-j>'] = actions.move_selection_next,
+ ['<C-k>'] = actions.move_selection_previous,
--["<C-c>"] = actions.close,
- ["<Esc>"] = actions.close, -- close w/ one esc
+ ['<Esc>'] = actions.close, -- close w/ one esc
--["<Esc>"] = "close", -- close w/ one esc
- ["<?>"] = actions.which_key, -- keys from pressing <C-/>
+ ['<?>'] = actions.which_key, -- keys from pressing <C-/>
- ["<Down>"] = actions.move_selection_next,
- ["<Up>"] = actions.move_selection_previous,
+ ['<Down>'] = actions.move_selection_next,
+ ['<Up>'] = actions.move_selection_previous,
- ["<CR>"] = actions.select_default,
- ["<C-x>"] = actions.select_horizontal,
- ["<C-y>"] = actions.select_vertical,
- ["<C-t>"] = actions.select_tab,
+ ['<CR>'] = actions.select_default,
+ ['<C-x>'] = actions.select_horizontal,
+ ['<C-y>'] = actions.select_vertical,
+ ['<C-t>'] = actions.select_tab,
- ["<C-u>"] = actions.preview_scrolling_up,
- ["<C-d>"] = actions.preview_scrolling_down,
+ ['<C-u>'] = actions.preview_scrolling_up,
+ ['<C-d>'] = actions.preview_scrolling_down,
- ["<PageUp>"] = actions.results_scrolling_up,
- ["<PageDown>"] = actions.results_scrolling_down,
+ ['<PageUp>'] = actions.results_scrolling_up,
+ ['<PageDown>'] = actions.results_scrolling_down,
- ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
- ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
- ["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
- ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
- ["<C-l>"] = actions.complete_tag,
- ["<C-_>"] = actions.which_key, -- keys from pressing <C-/>
+ ['<Tab>'] = actions.toggle_selection + actions.move_selection_worse,
+ ['<S-Tab>'] = actions.toggle_selection + actions.move_selection_better,
+ ['<C-q>'] = actions.send_to_qflist + actions.open_qflist,
+ ['<M-q>'] = actions.send_selected_to_qflist + actions.open_qflist,
+ ['<C-l>'] = actions.complete_tag,
+ ['<C-_>'] = actions.which_key, -- keys from pressing <C-/>
--["<C-o>"] = function(prompt_bufnr)
-- local selection = require("telescope.actions.state").get_selected_entry()
-- local dir = vim.fn.fnamemodify(selection.path, ":p:h")
@@ -102,36 +104,42 @@ require('telescope').setup({
-- -- Depending on what you want put `cd`, `lcd`, `tcd`
-- vim.cmd(string.format("silent lcd %s", dir))
--end,
- ["<esc>"] = actions.close,
- ["<q>"] = actions.close,
- ["<CR>"] = actions.select_default,
- ["<C-x>"] = actions.select_horizontal,
- ["<C-y>"] = actions.select_vertical,
- ["<C-t>"] = actions.select_tab,
-
- ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
- ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
- ["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
- ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
-
- ["j"] = actions.move_selection_next,
- ["k"] = actions.move_selection_previous,
- ["H"] = actions.move_to_top,
- ["M"] = actions.move_to_middle,
- ["L"] = actions.move_to_bottom,
-
- ["<Down>"] = actions.move_selection_next,
- ["<Up>"] = actions.move_selection_previous,
- ["gg"] = actions.move_to_top,
- ["G"] = actions.move_to_bottom,
-
- ["<C-u>"] = actions.preview_scrolling_up,
- ["<C-d>"] = actions.preview_scrolling_down,
-
- ["<PageUp>"] = actions.results_scrolling_up,
- ["<PageDown>"] = actions.results_scrolling_down,
-
- ["?"] = actions.which_key,
+ ['<esc>'] = actions.close,
+ ['<q>'] = actions.close,
+ ['<CR>'] = actions.select_default,
+ ['<C-x>'] = actions.select_horizontal,
+ ['<C-y>'] = actions.select_vertical,
+ ['<C-t>'] = actions.select_tab,
+
+ ['<Tab>'] = actions.toggle_selection + actions.move_selection_worse,
+ ['<S-Tab>'] = actions.toggle_selection + actions.move_selection_better,
+ ['<C-q>'] = actions.send_to_qflist + actions.open_qflist,
+ ['<M-q>'] = actions.send_selected_to_qflist + actions.open_qflist,
+
+ ['j'] = actions.move_selection_next,
+ ['k'] = actions.move_selection_previous,
+ ['H'] = actions.move_to_top,
+ ['M'] = actions.move_to_middle,
+ ['L'] = actions.move_to_bottom,
+
+ ['<Down>'] = actions.move_selection_next,
+ ['<Up>'] = actions.move_selection_previous,
+ ['gg'] = actions.move_to_top,
+ ['G'] = actions.move_to_bottom,
+
+ ['<C-u>'] = actions.preview_scrolling_up,
+ ['<C-d>'] = actions.preview_scrolling_down,
+
+ ['<PageUp>'] = actions.results_scrolling_up,
+ ['<PageDown>'] = actions.results_scrolling_down,
+ ['cd'] = function(prompt_bufnr)
+ local selection = require('telescope.actions.state').get_selected_entry()
+ local dir = vim.fn.fnamemodify(selection.path, ':p:h')
+ require('telescope.actions').close(prompt_bufnr)
+ -- Depending on what you want put `cd`, `lcd`, `tcd`
+ vim.cmd(string.format('silent lcd %s', dir))
+ end,
+ ['?'] = actions.which_key,
--["<C-o>"] = function(prompt_bufnr)
-- local selection = require("telescope.actions.state").get_selected_entry()
-- local dir = vim.fn.fnamemodify(selection.path, ":p:h")
@@ -146,9 +154,9 @@ require('telescope').setup({
filesize_limit = 3,
timeout = 250,
},
- selection_strategy = "reset",
- sorting_strategy = "ascending",
- scroll_strategy = "limit",
+ selection_strategy = 'reset',
+ sorting_strategy = 'ascending',
+ scroll_strategy = 'limit',
color_devicons = true,
layout_strategy = 'horizontal',
layout_config = {
@@ -156,14 +164,22 @@ require('telescope').setup({
height = 0.95,
preview_cutoff = 70,
width = 0.92,
- preview_width = { 0.55, max = 50 }
+ preview_width = { 0.55, max = 50 },
},
bottom_pane = {
height = 12,
preview_cutoff = 70,
- prompt_position = "bottom",
+ prompt_position = 'bottom',
},
},
+ find_files = {
+ --cwd = '%:p:h',
+ cwd = vim.fn.getcwd(),
+ prompt_prefix = ' ',
+ --hidden = true,
+ --no_ignore = false,
+ follow = true,
+ },
--pickers = {
-- live_grep = {
-- disable_coordinates = true,
@@ -208,13 +224,6 @@ require('telescope').setup({
-- prompt_prefix=' ',
-- show_line = false,
--},
- find_files = {
- cwd = '%:p:h',
- --cwd = vim.fn.getcwd(),
- prompt_prefix = ' ',
- hidden = true,
- follow = true,
- },
--keymaps = { prompt_prefix='? ' },
--oldfiles = { prompt_prefix=' ' },
--highlights = { prompt_prefix=' ' },
@@ -251,21 +260,21 @@ require('telescope').setup({
extensions = {
file_browser = {
- theme = "dropdown",
+ theme = 'dropdown',
-- disables netrw and use telescope-file-browser in its place
- hijack_netrw = true,
+ hijack_netrw = false,
mappings = {
-- your custom insert mode mappings
- ["i"] = {
- ["<C-w>"] = function()
- vim.cmd("normal vbd")
+ ['i'] = {
+ ['<C-w>'] = function()
+ vim.cmd('normal vbd')
end,
- --["<C-h>"] = fb_actions.goto_parent_dir,
+ ['<C-h>'] = fb_actions.goto_parent_dir,
},
- ["n"] = {
+ ['n'] = {
-- your custom normal mode mappings
- ["N"] = fb_actions.create,
- --["<C-h>"] = fb_actions.goto_parent_dir,
+ ['N'] = fb_actions.create,
+ ['<C-h>'] = fb_actions.goto_parent_dir,
--["/"] = function()
-- vim.cmd("startinsert")
--end,
@@ -281,14 +290,15 @@ require('telescope').setup({
-- have to be loaded after telescope setup/config
require('telescope').load_extension('fzf')
require('telescope').load_extension('ui-select')
-require("telescope").load_extension("file_browser")
+require('telescope').load_extension('file_browser')
require('telescope').load_extension('changed_files')
require('telescope').load_extension('media_files')
---require('telescope').extensions.notify.notify()
require('telescope').load_extension('notify')
require('telescope').load_extension('dap')
-require("telescope").load_extension("session-lens")
-require("telescope").load_extension("flutter")
+require('telescope').load_extension('session-lens')
+require('telescope').load_extension('flutter')
+require('telescope').load_extension('recent_files')
+--require('telescope').load_extension('projects')
--M.curbuf = function(opts)
-- opts = opts
@@ -301,119 +311,174 @@ require("telescope").load_extension("flutter")
--end
function M.find_configs()
- require("telescope.builtin").find_files {
+ require('telescope.builtin').find_files({
hidden = true,
no_ignore = false,
- prompt_title = " Find Configs",
- results_title = "Config Files",
- path_display = { "smart" },
+ prompt_title = ' Find Configs',
+ results_title = 'Config Files',
+ path_display = { 'smart' },
search_dirs = {
- "~/.config/nvim",
- "~/.config/zsh",
- "~/.config/tmux",
- "~/.config/X11",
- "~/.config/alacritty",
- "~/.config/kitty",
- "~/.config/wezterm",
- "~/.config/bspwm",
- "~/.config/sxhkd",
- "~/.config/picom",
- "~/.config/polybar",
- "~/.bashrc",
- "~/.ssh",
- "~/.vim",
- "~/.profile",
- "~/.zprofile",
- "~/README.md",
+ '~/.vim',
+ '~/.config/nvim',
+ '~/.config/zsh',
+ '~/.config/tmux',
+ '~/.config/X11',
+ '~/.config/alacritty',
+ '~/.config/kitty',
+ '~/.config/wezterm',
+ '~/.config/bspwm',
+ '~/.config/sxhkd',
+ '~/.config/picom',
+ '~/.config/polybar',
+ '~/.bashrc',
+ '~/.profile',
+ '~/.zprofile',
+ '~/.gitconfig',
+ '~/.gitsubtrees',
+ '~/.gitignore',
+ '~/.editorconfig',
+ '~/.prettierrc.yml',
+ '~/.ssh',
+ '~/README.md',
},
- -- cwd = "~/.config/nvim/",
file_ignore_patterns = {
- "~/.config/nvim/startup.log",
- "packer_compiled.lua",
- "resurrect",
- "tmux/plugins",
+ '/nvim/startup.log',
+ 'zsh/plugins',
+ 'packer_compiled.lua',
+ 'resurrect',
+ 'tmux/plugins',
--"^~/.config/tmux/plugins",
- "%.txt",
- ".git",
- "autoload/plugged",
- "plug.vim",
- "zcompdump",
+ '%.txt',
+ '.git/',
+ 'autoload/plugged',
+ 'plug.vim',
+ 'zcompdump',
},
- layout_strategy = "horizontal",
+ layout_strategy = 'horizontal',
layout_config = { preview_width = 0.65, width = 0.75 },
- }
+ })
end
function M.find_scripts()
- require("telescope.builtin").find_files {
+ require('telescope.builtin').find_files({
hidden = true,
no_ignore = true,
- prompt_title = " Find Scripts",
- path_display = { "smart" },
+ prompt_title = ' Find Scripts',
+ path_display = { 'smart' },
search_dirs = {
- "~/.local/bin/scripts",
+ '~/.local/bin/scripts',
},
- layout_strategy = "horizontal",
+ layout_strategy = 'horizontal',
layout_config = { preview_width = 0.65, width = 0.75 },
- }
+ })
end
+--function M.find_projects() -- aka Workspaces
+-- require('telescope.builtin').find_files({
+-- hidden = true,
+-- no_ignore = true,
+-- prompt_title = ' Find Projects',
+-- path_display = { 'smart' },
+-- search_dirs = {
+-- '~/projects',
+-- },
+-- layout_strategy = 'horizontal',
+-- layout_config = { preview_width = 0.65, width = 0.75 },
+-- })
+--end
+
function M.find_projects()
- require("telescope.builtin").find_files {
- hidden = true,
- no_ignore = true,
- prompt_title = " Find Projects",
- path_display = { "smart" },
- search_dirs = {
- "~/projects",
- },
- layout_strategy = "horizontal",
- layout_config = { preview_width = 0.65, width = 0.75 },
- }
+ local search_dir = '~/projects'
+ pickers
+ .new({}, {
+ prompt_title = 'Change Directory',
+ finder = finders.new_oneshot_job({
+ 'find',
+ vim.fn.expand(search_dir),
+ '-type',
+ 'd',
+ '-maxdepth',
+ '1',
+ }),
+ previewer = require('telescope.previewers').vim_buffer_cat.new({}),
+ sorter = config.generic_sorter({}),
+ attach_mappings = function(prompt_bufnr, map)
+ actions_set.select:replace(function()
+ local entry = actions_state.get_selected_entry()
+ if entry ~= nil then
+ local dir = entry.value
+ actions.close(prompt_bufnr, false)
+ vim.fn.chdir(dir)
+ vim.cmd('e .')
+ vim.cmd("echon ''")
+ print('cwd: ' .. vim.fn.getcwd())
+ end
+ end)
+ return true
+ end,
+ })
+ :find()
end
function M.grep_notes()
local opts = {}
opts.hidden = false
opts.search_dirs = {
- "~/documents/notes/",
+ '~/documents/notes/',
}
- opts.prompt_prefix = "  "
- opts.prompt_title = " Grep Notes"
- opts.path_display = { "smart" }
- require("telescope.builtin").live_grep(opts)
+ opts.prompt_prefix = '  '
+ opts.prompt_title = ' Grep Notes'
+ opts.path_display = { 'smart' }
+ require('telescope.builtin').live_grep(opts)
end
function M.find_notes()
- require("telescope.builtin").find_files {
- hidden = false,
- prompt_title = " Find Notes",
- path_display = { "smart" },
+ require('telescope.builtin').find_files({
+ hidden = true,
+ no_ignore = false,
+ prompt_title = ' Find Notes',
+ path_display = { 'smart' },
search_dirs = {
- "~/documents/notes/private/",
- "~/documents/notes",
+ '~/documents/notes/private/',
+ '~/documents/notes',
+ '~/notes/private',
+ '~/notes',
},
- --cwd = "~documents/notes",
- layout_strategy = "horizontal",
+ layout_strategy = 'horizontal',
layout_config = { preview_width = 0.65, width = 0.75 },
- }
+ })
+end
+
+function M.find_books()
+ require('telescope.builtin').find_files({
+ hidden = true,
+ no_ignore = false,
+ prompt_title = ' Find Books',
+ path_display = { 'smart' },
+ search_dirs = {
+ '~/documents/books',
+ '~/books',
+ },
+ layout_strategy = 'horizontal',
+ layout_config = { preview_width = 0.65, width = 0.75 },
+ })
end
function M.file_explorer()
- require("telescope.builtin").file_browser({
- prompt_title = "File Browser",
- cwd = "~",
- layout_strategy = "horizontal",
+ require('telescope.builtin').file_browser({
+ prompt_title = 'File Browser',
+ cwd = '~',
+ layout_strategy = 'horizontal',
})
end
function M.grep_current_dir()
- local buffer_dir = require("telescope.utils").buffer_dir()
+ local buffer_dir = require('telescope.utils').buffer_dir()
local opts = {
- prompt_title = "Live Grep in " .. buffer_dir,
+ prompt_title = 'Live Grep in ' .. buffer_dir,
cwd = buffer_dir,
}
- require("telescope.builtin").live_grep(opts)
+ require('telescope.builtin').live_grep(opts)
end
--------------------------------------------------------------------------------
@@ -427,7 +492,7 @@ local dropdown = require('telescope.themes').get_dropdown({
results_title = '',
layout_config = {
--anchor = "S",
- prompt_position = 'top'
+ prompt_position = 'top',
},
})
@@ -450,29 +515,22 @@ local with_title = function(opts, extra)
end
return vim.tbl_extend('force', opts, {
- prompt_title = title
+ prompt_title = title,
}, extra or {})
end
---vim.api.nvim_create_augroup('findhere', { clear = true })
---vim.api.nvim_command('augroup findhere')
---vim.api.nvim_command('autocmd!')
---vim.api.nvim_command('autocmd VimEnter * lua require("plugins/telescope").findhere()')
---vim.api.nvim_command('augroup END')
-
-
---local findhere = function()
+-- Find here
function M.findhere()
-- Open file browser if argument is a folder
local arg = vim.api.nvim_eval('argv(0)')
- if arg and (vim.fn.isdirectory(arg) ~= 0 or arg == "") then
+ if arg and (vim.fn.isdirectory(arg) ~= 0 or arg == '') then
vim.defer_fn(function()
require('telescope.builtin').find_files(with_title(dropdown))
--- require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({
--- hidden = true,
--- results_title = '',
--- layout_config = { prompt_position = 'top' },
--- }))
+ -- require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({
+ -- hidden = true,
+ -- results_title = '',
+ -- layout_config = { prompt_position = 'top' },
+ -- }))
end, 10)
end
end
@@ -480,10 +538,57 @@ end
-- Define the custom command findhere/startup
vim.cmd('command! Findhere lua require("plugins.telescope").findhere()')
--vim.cmd('command! Startup lua require("plugins.telescope").findhere()')
-
--vim.api.nvim_command('autocmd VimEnter * lua require("plugins/telescope").findhere()')
--- Merge the existing M table with the startup function table
---M = vim.tbl_extend('force', M, { findhere = findhere })
+-- Find dirs
+function M.find_dirs()
+ local root_dir = vim.fn.input('Enter the root directory: ')
+
+ -- Check if root_dir is empty
+ if root_dir == '' then
+ print('No directory entered. Aborting.')
+ return
+ end
+
+ local entries = {}
+
+ -- Use vim.fn.expand() to get an absolute path
+ local root_path = vim.fn.expand(root_dir)
+
+ local subdirs = vim.fn.readdir(root_path)
+ if subdirs then
+ for _, subdir in ipairs(subdirs) do
+ if vim.fn.isdirectory(root_path .. '/' .. subdir) == 1 then
+ table.insert(entries, subdir)
+ end
+ end
+ end
+
+ pickers
+ .new({}, {
+ prompt_title = 'Change Directory',
+ finder = finders.new_table({
+ results = entries,
+ }),
+ previewer = config.file_previewer({}),
+ sorter = config.generic_sorter({}),
+ attach_mappings = function(prompt_bufnr, map)
+ actions_set.select:replace(function()
+ local entry = actions_state.get_selected_entry()
+ if entry ~= nil then
+ local selected_subdir = entry.value
+ actions.close(prompt_bufnr, false)
+ local selected_path = root_path .. '/' .. selected_subdir
+ vim.fn.chdir(selected_path)
+ vim.cmd('e .')
+ vim.cmd("echon ''")
+ print('cwd: ' .. vim.fn.getcwd())
+ end
+ end)
+ return true
+ end,
+ })
+ :find()
+end
return M