feat: project.nvim

This commit is contained in:
punkfairie 2025-01-04 20:54:00 -08:00
parent 5d588eaf82
commit c474210010
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
4 changed files with 108 additions and 0 deletions

View file

@ -35,6 +35,7 @@ with final.pkgs.lib; let
nui-nvim
persistence-nvim
mini-hipatterns
project-nvim
# Colorscheme
rose-pine

View file

@ -8,6 +8,92 @@ local function pick(picker, opts)
end
end
local projectPick = nil
projectPick = function()
local has_project, _ = pcall(require, 'project_nvim')
if not has_project then
return
end
local fzf_lua = require('fzf-lua')
local project = require('project_nvim.project')
local history = require('project_nvim.utils.history')
local results = history.get_recent_projects()
local utils = require('fzf-lua.utils')
local function hl_validate(hl)
return not utils.is_hl_cleared(hl) and hl or nil
end
local function ansi_from_hl(hl, s)
return utils.ansi_from_hl(hl_validate(hl), s)
end
local opts = {
fzf_opts = {
['--header'] = string.format(
':: <%s> to %s | <%s> to %s | <%s> to %s | <%s> to %s | <%s> to %s',
ansi_from_hl('FzfLuaHeaderBind', 'ctrl-t'),
ansi_from_hl('FzfLuaHeaderText', 'tabedit'),
ansi_from_hl('FzfLuaHeaderBind', 'ctrl-s'),
ansi_from_hl('FzfLuaHeaderText', 'live_grep'),
ansi_from_hl('FzfLuaHeaderBind', 'ctrl-r'),
ansi_from_hl('FzfLuaHeaderText', 'oldfiles'),
ansi_from_hl('FzfLuaHeaderBind', 'ctrl-w'),
ansi_from_hl('FzfLuaHeaderText', 'change_dir'),
ansi_from_hl('FzfLuaHeaderBind', 'ctrl-d'),
ansi_from_hl('FzfLuaHeaderText', 'delete')
),
},
fzf_colors = true,
actions = {
['default'] = {
function(selected)
fzf_lua.files({ cwd = selected[1] })
end,
},
['ctrl-t'] = {
function(selected)
vim.cmd('tabedit')
fzf_lua.files({ cwd = selected[1] })
end,
},
['ctrl-s'] = {
function(selected)
fzf_lua.live_grep({ cwd = selected[1] })
end,
},
['ctrl-r'] = {
function(selected)
fzf_lua.oldfiles({ cwd = selected[1] })
end,
},
['ctrl-w'] = {
function(selected)
local path = selected[1]
local ok = project.set_pwd(path)
if ok then
vim.api.nvim_win_close(0, false)
vim.notify('Change project dir to ' .. path, 'info')
end
end,
},
['ctrl-d'] = function(selected)
local path = selected[1]
local choice =
vim.fn.confirm("Delete '" .. path .. "' project? ", '&Yes\n&No')
if choice == 1 then
history.delete_project({ value = path })
end
projectPick()
end,
},
}
fzf_lua.fzf_exec(results, opts)
end
return {
'fzf-lua',
cmd = 'FzfLua',
@ -25,6 +111,7 @@ return {
desc = 'find files (cwd)',
},
{ '<LEADER>fg', pick('git_files'), desc = 'find files (git)' },
{ '<LEADER>fp', projectPick, desc = 'projects' },
{ '<LEADER>fr', pick('oldfiles'), desc = 'recent' },
{
'<LEADER>fR',

View file

@ -5,4 +5,5 @@ return {
req('nui-nvim'),
req('persistance-nvim'),
req('plenary'),
req('project-nvim'),
}

View file

@ -0,0 +1,19 @@
return {
'project.nvim',
event = { 'DeferredUIEnter' },
after = function()
require('project_nvim').setup({
manual_mode = true,
})
local history = require('project_nvim.utils.history')
history.delete_project = function(project)
for k, v in pairs(history.recent_projects) do
if v == project.value then
history.recent_projects[k] = nil
return
end
end
end
end,
}