Skip to content

Commit

Permalink
Update telescope
Browse files Browse the repository at this point in the history
  • Loading branch information
richban committed Mar 10, 2024
1 parent 27fff66 commit ab2e9c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 230 deletions.
171 changes: 0 additions & 171 deletions dotfiles/config/nvim/lua/rb/telescope/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ function M.git_commits()
require("telescope.builtin").git_commits({ winblend = 5 })
end

function M.git_repos()
require("telescope").extensions.repo.list({})
end

function M.edit_neovim()
require("telescope.builtin").find_files({
prompt_title = "~ dotfiles ~",
shorten_path = false,
cwd = "~/.dotfiles/dotfiles/config/nvim",

layout_strategy = "horizontal",
layout_config = { preview_width = 0.65 },
})
end

function M.git_branches()
require("telescope.builtin").git_branches({
attach_mappings = function(_, map)
Expand All @@ -61,36 +46,6 @@ function M.git_branches()
})
end

function M.fd()
require("telescope.builtin").fd()
end

function M.media_files()
require("telescope").extensions.media_files.media_files()
end

function M.installed_plugins()
require("telescope.builtin").find_files({ cwd = vim.fn.stdpath("data") .. "/site/pack/packer/start/" })
end

function M.lsp_code_actions()
local opts = themes.get_dropdown({ winblend = 10, border = true, previewer = false, shorten_path = false })

require("telescope.builtin").lsp_code_actions(opts)
end

function M.live_grep()
require("telescope.builtin").live_grep({
-- shorten_path = true,
previewer = false,
fzf_separator = "|>",
})
end

function M.grep_prompt()
require("telescope.builtin").grep_string({ shorten_path = true, search = vim.fn.input("Grep String > ") })
end

function M.grep_last_search(opts)
opts = opts or {}

Expand All @@ -105,132 +60,6 @@ function M.grep_last_search(opts)
require("telescope.builtin").grep_string(opts)
end

-- function M.project_search()
-- require('telescope.builtin').find_files {
-- previewer = false,
-- layout_strategy = "vertical",
-- cwd = require('nvim_lsp.util').root_pattern(".git")(vim.fn.expand("%:p")),
-- }
-- end

function M.buffers()
require("telescope.builtin").buffers({ shorten_path = false })
end

function M.curbuf()
local opts = themes.get_dropdown({
winblend = 10,
border = true,
previewer = false,
shorten_path = false,
-- layout_strategy = 'current_buffer',
})
require("telescope.builtin").current_buffer_fuzzy_find(opts)
end

function M.help_tags()
require("telescope.builtin").help_tags({ show_version = true })
end

function M.search_all_files()
require("telescope.builtin").find_files({ find_command = { "rg", "--no-ignore", "--files" } })
end

function M.file_explorer()
local opts

opts = {
sorting_strategy = "ascending",
scroll_strategy = "cycle",
layout_config = { prompt_position = "top" },

attach_mappings = function(prompt_bufnr, map)
local current_picker = action_state.get_current_picker(prompt_bufnr)

local modify_cwd = function(new_cwd)
current_picker.cwd = new_cwd
current_picker:refresh(opts.new_finder(new_cwd), { reset_prompt = true })
end

map("i", "-", function()
modify_cwd(current_picker.cwd .. "/..")
end)

map("i", "~", function()
modify_cwd(vim.fn.expand("~"))
end)

local modify_depth = function(mod)
return function()
opts.depth = opts.depth + mod

local this_picker = action_state.get_current_picker(prompt_bufnr)
this_picker:refresh(opts.new_finder(current_picker.cwd), { reset_prompt = true })
end
end

map("i", "<M-=>", modify_depth(1))
map("i", "<M-+>", modify_depth(-1))

map("n", "yy", function()
local entry = action_state.get_selected_entry()
vim.fn.setreg("+", entry.value)
end)

return true
end,
}

require("telescope.builtin").file_browser(opts)
end

function M.file_browser()
require("telescope").extensions.file_browser.file_browser({ noremap = true })
end

function M.grep_notes()
local opts = {}
opts.hidden = true
-- opts.file_ignore_patterns = { 'thesaurus/'}
opts.search_dirs = { "~/Developer/richban.second.brain", "~/Developer/richban.ledger" }
opts.prompt_prefix = "  "
opts.prompt_title = " Grep Notes"
opts.path_display = { "shorten" }
require("telescope.builtin").live_grep(opts)
end

function M.find_notes()
require("telescope.builtin").find_files({
prompt_title = " Find Notes",
path_display = { "shorten" },
cwd = "~/Developer/richban.second.brain",
layout_strategy = "horizontal",
layout_config = { preview_width = 0.65, width = 0.75 },
})
end

function M.browse_notes()
require("telescope.builtin").file_browser({
prompt_title = " Browse Notes",
prompt_prefix = " ﮷ ",
cwd = "~/Developer/richban.second.brain",
layout_strategy = "horizontal",
layout_config = { preview_width = 0.65, width = 0.75 },
})
end

function M.find_configs()
require("telescope.builtin").find_files({
prompt_title = " NVim & Term Config Find",
results_title = "Config Files Results",
path_display = { "shorten" },
search_dirs = { "~/.dotfiles", "~/.config" },
cwd = "~/.config/",
layout_strategy = "horizontal",
layout_config = { preview_width = 0.65, width = 0.75 },
})
end

return setmetatable({}, {
__index = function(_, k)
reloader()
Expand Down
79 changes: 31 additions & 48 deletions dotfiles/config/nvim/lua/rb/telescope/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,46 @@ local map_tele = function(key, f, options, buffer)
end
end

vim.keymap.set("c", "<c-r><c-r>", "<Plug>(TelescopeFuzzyCommandSearch)", { noremap = false, nowait = true })
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>sh", builtin.help_tags, { desc = "[S]earch [H]elp" })
vim.keymap.set("n", "<leader>sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" })
vim.keymap.set("n", "<leader>sf", builtin.find_files, { desc = "[S]earch [F]iles" })
vim.keymap.set("n", "<leader>ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" })
vim.keymap.set("n", "<leader>sw", builtin.grep_string, { desc = "[S]earch current [W]ord" })
vim.keymap.set("n", "<leader>sg", builtin.live_grep, { desc = "[S]earch by [G]rep" })
vim.keymap.set("n", "<leader>sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" })
vim.keymap.set("n", "<leader>sr", builtin.resume, { desc = "[S]earch [R]esume" })
vim.keymap.set("n", "<leader>s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set("n", "<C-b>", builtin.buffers, { desc = "[ ] Find existing buffers" })
vim.keymap.set("n", "<leader><leader>", "<Cmd>Telescope frecency<CR>")

-- Dotfiles
map_tele("<leader>en", "edit_neovim")
map_tele("<leader>ec", "find_configs")
-- Slightly advanced example of overriding default behavior and theme
vim.keymap.set("n", "<leader>/", function()
-- You can pass additional configuration to telescope to change theme, layout, etc.
builtin.current_buffer_fuzzy_find(require("telescope.themes").get_dropdown({
winblend = 10,
previewer = false,
}))
end, { desc = "[/] Fuzzily search in current buffer" })

-- Also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set("n", "<leader>s/", function()
builtin.live_grep({
grep_open_files = true,
prompt_title = "Live Grep in Open Files",
})
end, { desc = "[S]earch [/] in Open Files" })

-- Search
map_tele("<leader>gw", "grep_string", {
short_path = true,
word_match = "-w",
only_sort_text = true,
layout_strategy = "vertical",
sorter = sorters.get_fzy_sorter(),
})
map_tele("<leader>f/", "grep_last_search", { layout_strategy = "vertical" })
-- Files
vim.keymap.set("n", "<leader><leader>", "<Cmd>Telescope frecency<CR>")
map_tele("<C-p>", "git_files")
map_tele("<leader>bg", "live_grep")
map_tele("<leader>ed", "fd")
map_tele("<leader>ea", "search_all_files")
-- FIXME:
map_tele("<leader>e", "file_explorer")
-- FIXME:
map_tele("<leader>em", "media_files")
map_tele("<leader>fb", "file_browser")
-- Nvim
map_tele("<C-b>", "buffers")
map_tele("<leader>ep", "installed_plugins")
-- FIXME:
map_tele("<leader>bf", "curbuf")
map_tele("<leader>th", "help_tags")

-- Workspaces
map_tele("<C-;>", "list_workspaces")

-- Git
-- map_tele("<space>gs", "git_status")
-- FIXME:
map_tele("<space>er", "git_repos")
map_tele("<space>gc", "git_commits")
map_tele("<space>gb", "git_branches")

map_tele("<leader>sc", "git_commits")
map_tele("<leader>sb", "git_branches")
map_tele("<leader>so", "vim_options")
map_tele("<leader>gp", "grep_prompt")

map_tele("<leader>/c", "commands")
map_tele("<leader>/r", "registers")
map_tele("<leader>/m", "marks")
map_tele("<leader>/t", "treesitter")

-- Telescope Meta
map_tele("<leader>fB", "builtin")

-- Notes
map_tele("<leader>gn", "grep_notes")
-- map_tele("<leader>nf", "find_notes")
-- map_tele("<leader>ne", "browse_notes")

return map_tele
16 changes: 5 additions & 11 deletions dotfiles/config/nvim/lua/rb/telescope/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,16 @@ require("telescope").setup({
find_cmd = "rg", -- find command (defaults to `fd`)
},
fzf_writer = { use_highlighter = false, minimum_grep_characters = 6 },
frecency = { workspaces = { ["conf"] = "~/Developer/dotfiles/" } },
workspaces = {
-- keep insert mode after selection in the picker, default is false
keep_insert = true,
frecency = {},
["ui-select"] = {
require("telescope.themes").get_dropdown(),
},
},
})

-- Load the fzy native extension at the start.
-- pcall(require('telescope').load_extension, "fzy_native")
-- require("telescope").load_extension("fzf")
pcall(require("telescope").load_extension, "fzf")
pcall(require("telescope").load_extension, "ui-select")

-- github CLI
pcall(require("telescope").load_extension, "gh")
Expand All @@ -126,9 +124,5 @@ pcall(require("telescope").load_extension, "dap")
pcall(require("telescope").load_extension, "file_browser")
pcall(require("telescope").load_extension, "project")

if pcall(require("telescope").load_extension, "frecency") then
-- frecency
vim.cmd([[highlight TelescopeBufferLoaded guifg=yellow]])
end

pcall(require("telescope").load_extension, "frecency")
pcall(require("telescope").load_extension, "projections")
1 change: 1 addition & 0 deletions system/home-manager/nvim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
telescope-frecency-nvim
telescope-dap-nvim
telescope-project-nvim
telescope-ui-select-nvim
sqlite-lua

vim-surround
Expand Down

0 comments on commit ab2e9c5

Please sign in to comment.