summaryrefslogtreecommitdiffstatshomepage
path: root/nvim/.config/nvim/lua/tobyvin/plugins/telescope.lua
blob: b7dd3a2904874d6d28f5ec6efd80306bf32c1f13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local M = {}

M.setup = function()
	local status_ok, telescope = pcall(require, "telescope")
	if not status_ok then
		vim.notify("Failed to load module 'telescope'", "error")
		return
	end

	local actions = require("telescope.actions")

	telescope.setup({
		defaults = {
			mappings = {
				i = {
					["<esc>"] = actions.close,
					["<C-h>"] = actions.which_key,
				},
			},
			file_ignore_patterns = { "^.git/", "^target/" },
			vimgrep_arguments = {
				"rg",
				"--color=never",
				"--no-heading",
				"--with-filename",
				"--line-number",
				"--column",
				"--hidden",
				"--smart-case",
				"--trim",
				"-u",
			},
			layout_strategy = "flex",
			scroll_strategy = "cycle",
			history = {
				path = vim.fn.stdpath("data") .. "/databases/telescope_history.sqlite3",
				limit = 100,
			},
		},
		pickers = {
			find_files = {
				theme = "dropdown",
				find_command = { "fd", "--type", "f", "--hidden", "--strip-cwd-prefix" },
			},
			live_grep = { theme = "ivy" },
			lsp_references = { theme = "dropdown" },
			lsp_code_actions = { theme = "dropdown" },
			lsp_definitions = { theme = "dropdown" },
			lsp_implementations = { theme = "dropdown" },
			buffers = {
				show_all_buffers = true,
				sort_lastused = true,
			},
		},
	})

	-- Extensions
	telescope.load_extension("smart_history")
	telescope.load_extension("fzf")
	telescope.load_extension("packer")
	telescope.load_extension("gh")

	local builtins = require("telescope.builtin")

	local nmap_find = require("tobyvin.utils").create_map_group("n", "<leader>f", { desc = "Find" })
	nmap_find("b", builtins.buffers, { desc = "Buffers" })
	nmap_find("c", builtins.command_history, { desc = "Command History" })
	nmap_find("C", builtins.commands, { desc = "Commands" })
	nmap_find("f", builtins.find_files, { desc = "Files" })
	nmap_find("g", builtins.live_grep, { desc = "Grep" })
	nmap_find("h", builtins.help_tags, { desc = "Help" })
	nmap_find("k", builtins.keymaps, { desc = "Keymaps" })
	nmap_find("r", builtins.resume, { desc = "Resume" })
	nmap_find("m", builtins.man_pages, { desc = "Man Pages" })
	nmap_find("o", builtins.oldfiles, { desc = "Old Files" })
	nmap_find("'", builtins.registers, { desc = "Registers" })
	nmap_find("t", builtins.colorscheme, { desc = "Colorscheme" })
	nmap_find("p", telescope.extensions.packer.packer, { desc = "Packer" })

	local nmap_git = require("tobyvin.utils").create_map_group("n", "<leader>g", { desc = "Git" })
	nmap_git("b", builtins.git_branches, { desc = "Checkout branch" })
	nmap_git("c", builtins.git_commits, { desc = "Checkout commit" })
	nmap_git("o", builtins.git_status, { desc = "Open changed file" })

	local nmap_git_wt = require("tobyvin.utils").create_map_group("n", "<leader>gw", { desc = "Worktree" })
	nmap_git_wt("s", telescope.extensions.git_worktree.git_worktrees, { desc = "Switch worktree" })
	nmap_git_wt("c", telescope.extensions.git_worktree.create_git_worktree, { desc = "Create worktree" })

	local nmap_git_gh = require("tobyvin.utils").create_map_group("n", "<leader>gG", { desc = "Github" })
	nmap_git_gh("i", telescope.extensions.gh.issues, { desc = "Issues" })
	nmap_git_gh("p", telescope.extensions.gh.pull_request, { desc = "Pull request" })
	nmap_git_gh("g", telescope.extensions.gh.gist, { desc = "Gist" })
	nmap_git_gh("r", telescope.extensions.gh.run, { desc = "Run" })
end

M.project_files = function()
	local opts = {} -- define here if you want to define something
	local ok = pcall(require("telescope.builtin").git_files, opts)
	if not ok then
		require("telescope.builtin").find_files(opts)
	end
end

return M