vim.pack.add({ "https://github.com/ibhagwan/fzf-lua", }, { load = function() end }) ---@param kind 'issue'|'pr' ---@param state 'all'|'open'|'closed' local function gh_picker(kind, state) if vim.fn.executable "gh" ~= 1 then vim.notify("gh CLI not found", vim.log.levels.WARN) return end local next_state = ({ all = "open", open = "closed", closed = "all" })[state] local label = kind == "pr" and "PRs" or "Issues" require("fzf-lua").fzf_exec(("gh %s list --limit 100 --state %s"):format(kind, state), { prompt = ("%s (%s)> "):format(label, state), header = ":: to toggle all/open/closed", actions = { ["default"] = function(selected) local num = selected[1]:match "^#?(%d+)" if num then vim.system { "gh", kind, "view", num, "--web" } end end, ["ctrl-o"] = function() gh_picker(kind, next_state) end, }, }) end return { "ibhagwan/fzf-lua", cmd = "FzfLua", before = function() pcall(vim.cmd.packadd, "nvim-web-devicons") pcall(vim.cmd.packadd, "nonicons.nvim") end, after = function() local fzf = require "fzf-lua" local opts = { "default-title", winopts = { border = "single", preview = { layout = "vertical", vertical = "down:50%", }, }, fzf_opts = { ["--layout"] = "reverse", }, } fzf.setup(opts) local ok, fzf_reload = pcall(require, "config.fzf_reload") if ok then fzf_reload.setup(opts) fzf_reload.reload() end end, keys = { { "", function() local fzf = require "fzf-lua" local git_dir = vim.fn.system("git rev-parse --git-dir 2>/dev/null"):gsub("\n", "") if vim.v.shell_error == 0 and git_dir ~= "" then fzf.git_files() else fzf.files() end end, }, { "ff", "FzfLua files" }, { "fg", "FzfLua live_grep" }, { "fb", "FzfLua buffers" }, { "fh", "FzfLua help_tags" }, { "fr", "FzfLua resume" }, { "fo", "FzfLua oldfiles" }, { "fc", "FzfLua commands" }, { "fk", "FzfLua keymaps" }, { "f/", "FzfLua search_history" }, { "f:", "FzfLua command_history" }, { "fe", "FzfLua files cwd=~/.config" }, { "gq", "FzfLua quickfix" }, { "gl", "FzfLua loclist" }, { "GB", "FzfLua git_branches" }, { "Gc", "FzfLua git_commits" }, { "Gs", "FzfLua git_status" }, { "Gp", function() gh_picker("pr", "open") end, }, { "Gi", function() gh_picker("issue", "open") end, }, }, }