Migrate from telescope to snacks.picker

This commit is contained in:
2025-07-14 15:14:06 +02:00
parent 13f09db11b
commit 4554653236
5 changed files with 131 additions and 230 deletions
+13 -4
View File
@@ -1,10 +1,6 @@
require("catppuccin").setup({
compile_path = vim.env.out .. "/lua/colors",
integrations = {
telescope = {
enabled = true,
style = "nvchad"
},
blink_cmp = true,
harpoon = true,
nvim_surround = true,
@@ -16,4 +12,17 @@ require("catppuccin").setup({
enabled = true,
},
},
custom_highlights = function(C)
return {
SnacksPickerMatch = { fg = C.mauve, style = { 'italic' } },
SnacksPickerInput = { fg = C.text, bg = C.crust },
SnacksPickerInputTitle = { fg = C.crust, bg = C.mauve },
SnacksPickerInputBorder = { fg = C.text, bg = C.crust },
SnacksPickerList = { bg = C.base },
SnacksPickerListCursorLine = { bg = C.crust },
SnacksPickerPreview = { bg = C.mantle },
SnacksPickerPreviewBorder = { fg = C.mantle, bg = C.mantle },
SnacksPickerPreviewTitle = { fg = C.mantle, bg = C.red },
}
end
})
+1 -6
View File
@@ -71,7 +71,6 @@ in
})
oil-nvim
telescope-fzf-native-nvim
harpoon2
gitsigns-nvim
@@ -94,7 +93,7 @@ in
noice-nvim
statuscol-nvim
telescope-ui-select-nvim
# telescope-ui-select-nvim
(snacks-nvim.overrideAttrs {
postPatch = "rm -rf queries";
})
@@ -113,8 +112,6 @@ in
# })
];
opt = [
telescope-nvim
# (mkPlugin telescope "telescope.nvim")
vim-illuminate
nvim-treesitter-textobjects
];
@@ -156,8 +153,6 @@ in
alejandra
pgformatter
csharpier
# might need to find a way to disable it for projects that use prettier but it's just more convenient to have it always on
# (for json or to allow use without an outer shell)
biome
ruff
];
-142
View File
@@ -1,142 +0,0 @@
return {
{
"telescope.nvim",
load = vim.cmd.packadd,
cmd = "Telescope",
keys = {
{ "<leader>f", "<cmd>Telescope find_files<cr>", desc = "Find Files" },
{ "<leader>F", "<cmd>Telescope ripgrep theme=ivy<cr>", desc = "Grep" },
-- { "<leader>gl", "<cmd>Telescope git_commits<cr>", desc = "Git log" },
-- { "<leader>gh", "<cmd>Telescope git_bcommits<cr>", desc = "Git history" },
-- { "<leader>gB", "<cmd>Telescope git_branches<cr>", desc = "Git branches" },
-- { "<leader>gs", "<cmd>Telescope git_status<cr>", desc = "Git status" },
{
"<leader>gl",
function()
require("telescope.builtin").git_commits({ cwd = vim.fs.root(0, ".git") })
end,
desc = "Git log"
},
{
"<leader>gh",
function()
require("telescope.builtin").git_bcommits({ cwd = vim.fs.root(0, ".git") })
end,
desc = "Git history"
},
{
"<leader>gB",
function()
require("telescope.builtin").git_branches({ cwd = vim.fs.root(0, ".git") })
end,
desc = "Git branches"
},
{
"<leader>gs",
function()
require("telescope.builtin").git_status({ cwd = vim.fs.root(0, ".git") })
end,
desc = "Git status"
},
{ "<leader>zh", "<cmd>Telescope help_tags<CR>", desc = "Read help" },
},
after = function()
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local function git_show()
local entry = action_state.get_selected_entry()
vim.cmd("Telescope git_show ref=" .. entry.value)
end
local function git_show_split(bufr)
actions.close(bufr)
local entry = action_state.get_selected_entry()
vim.cmd("Gedit " .. entry.value)
end
local function git_fixup(bufr)
actions.close(bufr)
local entry = action_state.get_selected_entry()
vim.cmd("G commit --fixup=" .. entry.value)
end
local telescope = require("telescope")
telescope.setup({
defaults = {
prompt_prefix = "",
selection_caret = "",
sorting_strategy = "ascending",
layout_config = {
horizontal = {
prompt_position = "top",
}
},
mappings = {
i = {
["<esc>"] = actions.close,
["<C-c>"] = actions.close,
["<C-a>"] = function() vim.cmd "normal! I" end,
["<C-e>"] = function() vim.cmd "startinsert!" end,
},
}
},
pickers = {
find_files = {
hidden = true,
-- remove .git directory
find_command = { "fd", "--type", "f", "--strip-cwd-prefix", "-E", ".git" },
},
git_commits = {
-- use_file_path = true,
mappings = {
i = {
["<CR>"] = git_show,
["<C-g>"] = git_show_split,
["<C-f>"] = git_fixup,
},
},
},
git_bcommits = {
-- use_file_path = true,
mappings = {
i = {
["<CR>"] = git_show,
["<C-g>"] = git_show_split,
["<C-f>"] = git_fixup,
["<C-v>"] = function(bufr)
actions.close(bufr)
local entry = action_state.get_selected_entry()
vim.cmd("Gvsplit " .. entry.value .. ":" .. entry.current_file)
end,
["<C-s>"] = function(bufr)
actions.close(bufr)
local entry = action_state.get_selected_entry()
vim.cmd("Gsplit " .. entry.value .. ":" .. entry.current_file)
end,
},
},
},
git_branches = {
-- use_file_path = true,
show_remote_tracking_branches = false,
mappings = {
i = {
["<CR>"] = actions.git_switch_branch
},
}
},
git_status = {
-- use_file_path = true,
},
},
})
telescope.load_extension("fzf")
telescope.load_extension("ripgrep")
telescope.load_extension("git_show")
telescope.load_extension("ui-select")
end
},
}
+117 -1
View File
@@ -109,11 +109,127 @@ return {
},
},
},
picker = {
win = {
input = {
keys = {
["<Esc>"] = { "close", mode = { "n", "i" } },
["<c-c>"] = { "close", mode = { "n", "i" } },
["<c-u>"] = { "preview_scroll_up", mode = { "i", "n" } },
["<c-d>"] = { "preview_scroll_down", mode = { "i", "n" } },
["<C-a>"] = function() vim.cmd "normal! I" end,
["<C-e>"] = function() vim.cmd "startinsert!" end,
},
},
},
sources = {
files = {
hidden = true,
},
grep = {
layout = "ivy",
hidden = true,
},
git_branches = {
all = true,
},
-- TODO: make a git_show picker like i did with telescope
git_log = {
confirm = false,
},
git_log_file = {
confirm = false,
},
},
layouts = {
default = {
layout = {
box = 'horizontal',
backdrop = false,
width = 0.8,
height = 0.9,
border = 'none',
{
box = 'vertical',
{
win = 'input',
title = ' {source} {live} ',
title_pos = 'center',
border = 'solid',
height = 1,
},
{
win = 'list',
border = 'solid',
},
},
{
win = 'preview',
width = 0.5,
title = ' {preview} ',
title_pos = 'center',
border = "top",
},
},
},
ivy = {
layout = {
box = "horizontal",
backdrop = false,
width = 0,
height = 0.5,
border = "none",
position = "bottom",
{
box = "vertical",
border = "none",
{
win = "input",
title = " {title} {live} ",
height = 1,
border = "solid"
},
{ win = "list", border = "solid" },
},
{
win = "preview",
title = " {preview} ",
border = "top",
width = vim.o.columns <= 125 and 0.7 or 0.55,
},
},
},
},
},
},
after = function(plug)
require("snacks").setup(plug.opts)
vim.keymap.set("n", "<leader>zz", function() require("snacks").zen() end, { desc = "Toggle zen mode" })
vim.keymap.set("n", "<leader>zz", function() Snacks.zen() end, { desc = "Toggle zen mode" })
vim.keymap.set("n", "<leader>f", function()
Snacks.picker.files()
end, { desc = "Find files" })
vim.keymap.set("n", "<leader>F", function()
Snacks.picker.grep()
end, { desc = "Grep" })
vim.keymap.set("n", "<leader>gl", function()
Snacks.picker.git_log()
end, { desc = "Git log" })
vim.keymap.set("n", "<leader>gh", function()
Snacks.picker.git_log_file()
end, { desc = "Git logs buffer" })
vim.keymap.set("n", "<leader>gB", function()
Snacks.picker.git_branches()
end, { desc = "Git branches" })
vim.keymap.set("n", "<leader>gs", function()
Snacks.picker.git_status()
end, { desc = "Git status" })
end,
},
}
@@ -1,77 +0,0 @@
local conf = require("telescope.config").values
local finders = require("telescope.finders")
local make_entry = require("telescope.make_entry")
local pickers = require("telescope.pickers")
local ripgrep = function(opts)
opts = opts or {}
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
opts.pattern = opts.pattern or "%s"
local custom_grep = finders.new_async_job {
command_generator = function(prompt)
if not prompt or prompt == "" then
return nil
end
local split = vim.split(prompt, " ")
local search = split[1]
local glob = {}
if not search or search == "" then
return nil
end
if split[2] ~= nil and #split[2] > 0 then
local g = split[2]
local glob_flag = "--iglob"
-- switch to case sensitive glob if there's an uppercase letter.
if g:match("%u") then
glob_flag = "--glob"
end
if g:match("^[%w/%._-]") then
g = "*" .. g
elseif g:sub(1, 1) == "^" then
g = g:sub(2)
end
if g:match("[%w/%._-]$") then
g = g .. "*"
elseif g:sub(#g) == "$" then
g = g:sub(1, #g - 1)
end
glob = { glob_flag, g }
end
return vim.iter({
{ "rg", "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", },
{ "--hidden", "--smart-case", },
-- always ignore files in the .git dir
{ "--iglob", "!.git" },
glob,
{ "--", search },
}):flatten():totable()
end,
entry_maker = make_entry.gen_from_vimgrep(opts),
cwd = opts.cwd,
}
pickers
.new(opts, {
debounce = 100,
prompt_title = "Live Grep",
finder = custom_grep,
previewer = conf.grep_previewer(opts),
sorter = require("telescope.sorters").empty(),
})
:find()
end
return require("telescope").register_extension {
setup = function() end,
exports = {
ripgrep = ripgrep,
},
}