mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-07 07:54:38 +02:00
refactor: LazyVim.pick
This commit is contained in:
parent
1b34b481c8
commit
e29ad4a14e
6 changed files with 144 additions and 96 deletions
|
@ -179,17 +179,17 @@ return {
|
|||
"<cmd>Telescope buffers sort_mru=true sort_lastused=true<cr>",
|
||||
desc = "Switch Buffer",
|
||||
},
|
||||
{ "<leader>/", LazyVim.telescope("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>:", "<cmd>Telescope command_history<cr>", desc = "Command History" },
|
||||
{ "<leader><space>", LazyVim.telescope("files"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader><space>", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" },
|
||||
-- find
|
||||
{ "<leader>fb", "<cmd>Telescope buffers sort_mru=true sort_lastused=true<cr>", desc = "Buffers" },
|
||||
{ "<leader>fc", LazyVim.telescope.config_files(), desc = "Find Config File" },
|
||||
{ "<leader>ff", LazyVim.telescope("files"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader>fF", LazyVim.telescope("files", { cwd = false }), desc = "Find Files (cwd)" },
|
||||
{ "<leader>fc", LazyVim.pick.config_files(), desc = "Find Config File" },
|
||||
{ "<leader>ff", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader>fF", LazyVim.pick("auto", { root = false }), desc = "Find Files (cwd)" },
|
||||
{ "<leader>fg", "<cmd>Telescope git_files<cr>", desc = "Find Files (git-files)" },
|
||||
{ "<leader>fr", "<cmd>Telescope oldfiles<cr>", desc = "Recent" },
|
||||
{ "<leader>fR", LazyVim.telescope("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
|
||||
{ "<leader>fR", LazyVim.pick("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
|
||||
-- git
|
||||
{ "<leader>gc", "<cmd>Telescope git_commits<CR>", desc = "Commits" },
|
||||
{ "<leader>gs", "<cmd>Telescope git_status<CR>", desc = "Status" },
|
||||
|
@ -201,8 +201,8 @@ return {
|
|||
{ "<leader>sC", "<cmd>Telescope commands<cr>", desc = "Commands" },
|
||||
{ "<leader>sd", "<cmd>Telescope diagnostics bufnr=0<cr>", desc = "Document Diagnostics" },
|
||||
{ "<leader>sD", "<cmd>Telescope diagnostics<cr>", desc = "Workspace Diagnostics" },
|
||||
{ "<leader>sg", LazyVim.telescope("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>sG", LazyVim.telescope("live_grep", { cwd = false }), desc = "Grep (cwd)" },
|
||||
{ "<leader>sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" },
|
||||
{ "<leader>sh", "<cmd>Telescope help_tags<cr>", desc = "Help Pages" },
|
||||
{ "<leader>sH", "<cmd>Telescope highlights<cr>", desc = "Search Highlight Groups" },
|
||||
{ "<leader>sj", "<cmd>Telescope jumplist<cr>", desc = "Jumplist" },
|
||||
|
@ -213,11 +213,11 @@ return {
|
|||
{ "<leader>so", "<cmd>Telescope vim_options<cr>", desc = "Options" },
|
||||
{ "<leader>sR", "<cmd>Telescope resume<cr>", desc = "Resume" },
|
||||
{ "<leader>sq", "<cmd>Telescope quickfix<cr>", desc = "Quickfix List" },
|
||||
{ "<leader>sw", LazyVim.telescope("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.telescope("grep_string", { cwd = false, word_match = "-w" }), desc = "Word (cwd)" },
|
||||
{ "<leader>sw", LazyVim.telescope("grep_string"), mode = "v", desc = "Selection (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.telescope("grep_string", { cwd = false }), mode = "v", desc = "Selection (cwd)" },
|
||||
{ "<leader>uC", LazyVim.telescope("colorscheme", { enable_preview = true }), desc = "Colorscheme with Preview" },
|
||||
{ "<leader>sw", LazyVim.pick("grep_string", { word_match = "-w" }), desc = "Word (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.pick("grep_string", { root = false, word_match = "-w" }), desc = "Word (cwd)" },
|
||||
{ "<leader>sw", LazyVim.pick("grep_string"), mode = "v", desc = "Selection (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.pick("grep_string", { root = false }), mode = "v", desc = "Selection (cwd)" },
|
||||
{ "<leader>uC", LazyVim.pick("colorscheme", { enable_preview = true }), desc = "Colorscheme with Preview" },
|
||||
{
|
||||
"<leader>ss",
|
||||
function()
|
||||
|
@ -246,12 +246,12 @@ return {
|
|||
local find_files_no_ignore = function()
|
||||
local action_state = require("telescope.actions.state")
|
||||
local line = action_state.get_current_line()
|
||||
LazyVim.telescope("find_files", { no_ignore = true, default_text = line })()
|
||||
LazyVim.pick("find_files", { no_ignore = true, default_text = line })()
|
||||
end
|
||||
local find_files_with_hidden = function()
|
||||
local action_state = require("telescope.actions.state")
|
||||
local line = action_state.get_current_line()
|
||||
LazyVim.telescope("find_files", { hidden = true, default_text = line })()
|
||||
LazyVim.pick("find_files", { hidden = true, default_text = line })()
|
||||
end
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,29 +1,19 @@
|
|||
local M = {}
|
||||
---@class FzfLuaOpts: lazyvim.util.pick.Opts
|
||||
---@field cmd string?
|
||||
|
||||
---@class FzfLuaOpts: table<string, any>
|
||||
---@field cwd boolean|string
|
||||
LazyVim.pick.commands = {
|
||||
files = "files",
|
||||
}
|
||||
|
||||
---@param opts? {cwd?:string|boolean}
|
||||
function M.fzf(builtin, opts)
|
||||
---@param command string
|
||||
---@param opts? FzfLuaOpts
|
||||
LazyVim.pick._open = function(command, opts)
|
||||
opts = opts or {}
|
||||
|
||||
return function()
|
||||
local dir = opts.cwd == true and vim.uv.cwd() or LazyVim.root()
|
||||
opts.cwd = dir
|
||||
if
|
||||
builtin == "files"
|
||||
and vim.uv.fs_stat(dir .. "/.git")
|
||||
and not vim.uv.fs_stat(dir .. "/.ignore")
|
||||
and not vim.uv.fs_stat(dir .. "/.rgignore")
|
||||
then
|
||||
if opts.cmd == nil then
|
||||
opts.cmd = "git ls-files --exclude-standard --cached --others"
|
||||
end
|
||||
builtin = "git_files"
|
||||
end
|
||||
|
||||
return require("fzf-lua")[builtin](opts)
|
||||
if opts.cmd == nil and command == "git_files" and opts.show_untracked then
|
||||
opts.cmd = "git ls-files --exclude-standard --cached --others"
|
||||
end
|
||||
return require("fzf-lua")[command](opts)
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -74,17 +64,17 @@ return {
|
|||
"<cmd>FzfLua buffers sort_mru=true sort_lastused=true<cr>",
|
||||
desc = "Switch Buffer",
|
||||
},
|
||||
{ "<leader>/", M.fzf("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>/", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>:", "<cmd>FzfLua command_history<cr>", desc = "Command History" },
|
||||
{ "<leader><space>", M.fzf("files"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader><space>", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" },
|
||||
-- find
|
||||
{ "<leader>fb", "<cmd>FzfLua buffers sort_mru=true sort_lastused=true<cr>", desc = "Buffers" },
|
||||
{ "<leader>fc", M.fzf("files", { cwd = vim.fn.stdpath("config") }), desc = "Find Config File" },
|
||||
{ "<leader>ff", M.fzf("files"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader>fF", M.fzf("files", { cwd = true }), desc = "Find Files (cwd)" },
|
||||
{ "<leader>fc", LazyVim.pick.config_files(), desc = "Find Config File" },
|
||||
{ "<leader>ff", LazyVim.pick("auto"), desc = "Find Files (Root Dir)" },
|
||||
{ "<leader>fF", LazyVim.pick("auto", { root = false }), desc = "Find Files (cwd)" },
|
||||
{ "<leader>fg", "<cmd>FzfLua git_files<cr>", desc = "Find Files (git-files)" },
|
||||
{ "<leader>fr", "<cmd>FzfLua oldfiles<cr>", desc = "Recent" },
|
||||
{ "<leader>fR", M.fzf("oldfiles", { cwd = vim.uv.cwd() }), desc = "Recent (cwd)" },
|
||||
{ "<leader>fR", LazyVim.pick("oldfiles", { root = false }), desc = "Recent (cwd)" },
|
||||
-- git
|
||||
{ "<leader>gc", "<cmd>FzfLua git_commits<CR>", desc = "Commits" },
|
||||
{ "<leader>gs", "<cmd>FzfLua git_status<CR>", desc = "Status" },
|
||||
|
@ -96,8 +86,8 @@ return {
|
|||
{ "<leader>sC", "<cmd>FzfLua commands<cr>", desc = "Commands" },
|
||||
{ "<leader>sd", "<cmd>FzfLua diagnostics_document<cr>", desc = "Document Diagnostics" },
|
||||
{ "<leader>sD", "<cmd>FzfLua diagnostics_workspace<cr>", desc = "Workspace Diagnostics" },
|
||||
{ "<leader>sg", M.fzf("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>sG", M.fzf("live_grep", { cwd = true }), desc = "Grep (cwd)" },
|
||||
{ "<leader>sg", LazyVim.pick("live_grep"), desc = "Grep (Root Dir)" },
|
||||
{ "<leader>sG", LazyVim.pick("live_grep", { root = false }), desc = "Grep (cwd)" },
|
||||
{ "<leader>sh", "<cmd>FzfLua help_tags<cr>", desc = "Help Pages" },
|
||||
{ "<leader>sH", "<cmd>FzfLua highlights<cr>", desc = "Search Highlight Groups" },
|
||||
{ "<leader>sj", "<cmd>FzfLua jumps<cr>", desc = "Jumplist" },
|
||||
|
@ -107,11 +97,11 @@ return {
|
|||
{ "<leader>sm", "<cmd>FzfLua marks<cr>", desc = "Jump to Mark" },
|
||||
{ "<leader>sR", "<cmd>FzfLua resume<cr>", desc = "Resume" },
|
||||
{ "<leader>sq", "<cmd>FzfLua quickfix<cr>", desc = "Quickfix List" },
|
||||
{ "<leader>sw", M.fzf("grep_cword"), desc = "Word (Root Dir)" },
|
||||
{ "<leader>sW", M.fzf("grep_cword", { cwd = true }), desc = "Word (cwd)" },
|
||||
{ "<leader>sw", M.fzf("grep_visual"), mode = "v", desc = "Selection (Root Dir)" },
|
||||
{ "<leader>sW", M.fzf("grep_visual", { cwd = true }), mode = "v", desc = "Selection (cwd)" },
|
||||
{ "<leader>uC", M.fzf("colorschemes"), desc = "Colorscheme with Preview" },
|
||||
{ "<leader>sw", LazyVim.pick("grep_cword"), desc = "Word (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.pick("grep_cword", { root = false }), desc = "Word (cwd)" },
|
||||
{ "<leader>sw", LazyVim.pick("grep_visual"), mode = "v", desc = "Selection (Root Dir)" },
|
||||
{ "<leader>sW", LazyVim.pick("grep_visual", { root = false }), mode = "v", desc = "Selection (cwd)" },
|
||||
{ "<leader>uC", LazyVim.pick("colorschemes"), desc = "Colorscheme with Preview" },
|
||||
{
|
||||
"<leader>ss",
|
||||
function()
|
||||
|
|
|
@ -343,11 +343,11 @@ return {
|
|||
header = vim.split(logo, "\n"),
|
||||
-- stylua: ignore
|
||||
center = {
|
||||
{ action = LazyVim.telescope("files"), desc = " Find File", icon = " ", key = "f" },
|
||||
{ action = LazyVim.pick(), desc = " Find File", icon = " ", key = "f" },
|
||||
{ action = "ene | startinsert", desc = " New File", icon = " ", key = "n" },
|
||||
{ action = "Telescope oldfiles", desc = " Recent Files", icon = " ", key = "r" },
|
||||
{ action = "Telescope live_grep", desc = " Find Text", icon = " ", key = "g" },
|
||||
{ action = [[lua LazyVim.telescope.config_files()()]], desc = " Config", icon = " ", key = "c" },
|
||||
{ action = LazyVim.pick("oldfiles"), desc = " Recent Files", icon = " ", key = "r" },
|
||||
{ action = LazyVim.pick("live_grep"), desc = " Find Text", icon = " ", key = "g" },
|
||||
{ action = LazyVim.pick.config_files(), desc = " Config", icon = " ", key = "c" },
|
||||
{ action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" },
|
||||
{ action = "LazyExtras", desc = " Lazy Extras", icon = " ", key = "x" },
|
||||
{ action = "Lazy", desc = " Lazy", icon = " ", key = "l" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue