feat(lua): add custom startup picker and snacks configuration
This commit is contained in:
1 parent
393011a521
commit
b4b165fb96
3 files changed
+131
-11
No files matched your search
@@ -16,6 +16,7 @@ return {
|
||||
"AstroNvim/astrocore",
|
||||
---@type AstroCoreOpts
|
||||
opts = {
|
||||
|
||||
sessions = {
|
||||
-- Configure auto saving
|
||||
autosave = {
|
||||
@@ -104,6 +105,76 @@ return {
|
||||
end,
|
||||
},
|
||||
},
|
||||
-- Show recent files or git repos on startup
|
||||
startup_picker = {
|
||||
{
|
||||
event = "VimEnter",
|
||||
desc = "Show recent files for git repo or git repos picker on startup",
|
||||
callback = function()
|
||||
-- Skip if opening with arguments (files, directories, stdin)
|
||||
if vim.fn.argc() > 0 then return end
|
||||
|
||||
-- Skip if current buffer has content
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
if #lines > 1 or (#lines == 1 and lines[1] ~= "") then return end
|
||||
|
||||
-- Delay to ensure everything is loaded
|
||||
vim.defer_fn(function()
|
||||
-- Check if we're in a git repo
|
||||
local git_dir = vim.fn.systemlist("git rev-parse --git-dir 2>/dev/null")[1]
|
||||
local is_git_repo = vim.v.shell_error == 0 and git_dir ~= nil and git_dir ~= ""
|
||||
|
||||
if is_git_repo then
|
||||
-- In a git repo: show recent files
|
||||
require("snacks").picker.recent()
|
||||
else
|
||||
-- Not in a git repo: show git repos using ghq
|
||||
if vim.fn.executable "ghq" == 1 then
|
||||
-- Get list of repos from ghq
|
||||
local repos = vim.fn.systemlist "ghq list --full-path"
|
||||
if #repos > 0 then
|
||||
-- Build items list with formatted display
|
||||
local items = {}
|
||||
for _, repo_path in ipairs(repos) do
|
||||
-- Extract org/repo from path
|
||||
local display = repo_path:match "github%.com/([^/]+/[^/]+)" or vim.fn.fnamemodify(repo_path, ":t")
|
||||
table.insert(items, {
|
||||
text = display,
|
||||
path = repo_path,
|
||||
})
|
||||
end
|
||||
|
||||
-- Use snacks picker to show repos
|
||||
require("snacks").picker({
|
||||
title = "Git Repositories",
|
||||
layout = { preview = false },
|
||||
items = items,
|
||||
format = function(item)
|
||||
return { { item.text } }
|
||||
end,
|
||||
confirm = function(picker, item)
|
||||
picker:close()
|
||||
-- Change to the selected repo directory
|
||||
vim.cmd("cd " .. item.path)
|
||||
-- Show recent files from the new directory
|
||||
vim.defer_fn(function()
|
||||
require("snacks").picker.recent()
|
||||
end, 50)
|
||||
end,
|
||||
})
|
||||
else
|
||||
-- Fallback to recent files if no repos found
|
||||
require("snacks").picker.recent()
|
||||
end
|
||||
else
|
||||
-- ghq not available, just show recent files
|
||||
require("snacks").picker.recent()
|
||||
end
|
||||
end
|
||||
end, 10)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- vim options can be configured here
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
--- Bufferline configuration with AstroNvim integration
|
||||
--- Provides enhanced buffer/tab management with diagnostics and custom close handlers
|
||||
--- Overrides and customizations for bufferline.nvim
|
||||
--- Relies on astrocommunity.bars-and-lines.bufferline-nvim for base setup
|
||||
--- @module plugins.bufferline
|
||||
|
||||
---@type LazySpec
|
||||
return {
|
||||
"akinsho/bufferline.nvim",
|
||||
version = "*",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons", "AstroNvim/astrocore" },
|
||||
event = "VeryLazy",
|
||||
config = function()
|
||||
local bufferline = require "bufferline"
|
||||
local groups = require "bufferline.groups"
|
||||
|
||||
bufferline.setup {
|
||||
opts = {
|
||||
options = {
|
||||
mode = "buffers",
|
||||
numbers = "none",
|
||||
-- Use AstroCore buffer close handler for proper cleanup
|
||||
close_command = function(n) require("astrocore.buffer").close(n) end,
|
||||
right_mouse_command = function(n) require("astrocore.buffer").close(n) end,
|
||||
separator_style = "thick",
|
||||
@@ -37,8 +32,10 @@ return {
|
||||
close_icon = "",
|
||||
left_trunc_marker = "",
|
||||
right_trunc_marker = "",
|
||||
-- Offset for snacks picker to prevent overlap
|
||||
offsets = {
|
||||
{ filetype = "snacks_picker", text = "", padding = 0 },
|
||||
{ filetype = "neo-tree", text = "", padding = 0 },
|
||||
},
|
||||
},
|
||||
highlights = {
|
||||
@@ -54,6 +51,5 @@ return {
|
||||
error = { fg = "#f38ba8" },
|
||||
error_selected = { fg = "#f38ba8", bold = true },
|
||||
},
|
||||
}
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
--- Snacks.nvim configuration
|
||||
--- Overrides and customizations for snacks.nvim features
|
||||
--- Relies on astrocommunity.recipes.telescope-nvim-snacks for base setup
|
||||
--- @module plugins.snacks
|
||||
|
||||
return {
|
||||
"folke/snacks.nvim",
|
||||
opts = {
|
||||
-- Disable dashboard - we use custom startup picker in astrocore.lua
|
||||
dashboard = { enabled = false },
|
||||
|
||||
-- Enable snacks features we use throughout config
|
||||
bigfile = { enabled = true },
|
||||
input = { enabled = true },
|
||||
notifier = { enabled = true },
|
||||
picker = { enabled = true },
|
||||
quickfile = { enabled = true },
|
||||
rename = { enabled = true },
|
||||
scope = { enabled = true },
|
||||
scroll = { enabled = true },
|
||||
statuscolumn = { enabled = true },
|
||||
terminal = { enabled = true },
|
||||
words = { enabled = true },
|
||||
indent = { enabled = true },
|
||||
|
||||
-- Terminal styles
|
||||
styles = {
|
||||
terminal = {
|
||||
bo = { filetype = "snacks_terminal" },
|
||||
wo = {},
|
||||
keys = {
|
||||
q = "hide",
|
||||
term_normal = {
|
||||
"<esc>",
|
||||
function(self)
|
||||
self.esc_timer = self.esc_timer or (vim.uv or vim.loop).new_timer()
|
||||
if self.esc_timer:is_active() then
|
||||
self.esc_timer:stop()
|
||||
vim.cmd("stopinsert")
|
||||
else
|
||||
self.esc_timer:start(200, 0, function() end)
|
||||
return "<esc>"
|
||||
end
|
||||
end,
|
||||
mode = "t",
|
||||
expr = true,
|
||||
desc = "Double escape to normal mode",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user